# Perch ~ Passing variables into templates

**URL:** <https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805>\
**Category:** Freeway\
**Created:** [February 24, 2015, 3:50pm UTC](https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805 "2015-02-24T15:50:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davedesigner](https://discourse.softpress.com/user_avatar/discourse.softpress.com/davedesigner/32/61_2.png) [@davedesigner](https://discourse.softpress.com/u/davedesigner)\
**Post date:** [February 24, 2015, 3:50pm UTC](https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805/1 "2015-02-24T15:50:32Z")

</div>

I’m hoping someone here has worked with Perch and with a more php dev background help me get my head round a Perch problem.

I’ve worked with Perch CMS and Freeway which generally is very good but certain areas without a full PHP developer background the Perch support/forum can be a bit lacking as they assume shall I say “you should know this” please go away attitude probably because the developers of Perch are way too busy and other users either don’t know or the devs don’t need to ask of be there. This really highlights how good the Freeway Forum is to all users no matter what level they are at.

Anyway getting to the problem…

The Events App out of the blocks does much what you need to however if you add using Event Categories it can only sort the current month by category. You can only Click next month by date to show all…

…/events/index.php?d=2015-03/

So you need…

…./events/index.php?d=2015-03&cat=mycat

To make it work. Fine so need to GET the cat variable off a URL for the events app into a Events Template I can do this with PHP but Perch no I need this is the Event templates…

They say to use…

> **[Passing variables into templates](http://docs.grabaperch.com/templates/passing-variables-into-templates/)**
>
> Perch documentation

```auto
<?php   
PerchSystem::set_var('lang', 'en');
perch_content_custom('My region', array(        
'template'=>'template.html'
));
?>

```

Then in your template:

```auto
<a href="/<perch:content id="lang" />/contact/">Contact Us</a>

```

I can’t seem to get this to work probably because I need a breakdown as to what this first part of the code is doing. To me this is just manually setting a variable in the page is that right? Or can ‘en’ be ‘cat’ from the URL and naming it lang?

Also the Perch Events app does not have a region to put in My Region does it? Event is an app not general content

Have anyone worked with Perch to this extent?

–

David Owen

* * *

freewaytalk mailing list  
email@hidden  
Update your subscriptions at:  
[http://freewaytalk.net/person/options](http://freewaytalk.net/person/options)

---

<div class="post-metadata">

**Author:** ![Todd1](https://discourse.softpress.com/letter_avatar_proxy/v4/letter/t/838e76/32.png) [@Todd1](https://discourse.softpress.com/u/Todd1)\
**Post date:** [February 24, 2015, 5:36pm UTC](https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805/2 "2015-02-24T17:36:24Z")

</div>

I had to do something vaguely similar with Events a few years ago for a now defunct site. I can’t recall specifics at this point but I’ll see if I still have the code from that job lying around. No promises.

Although the syntax is different this feels kind of similar to how I filter terms by passing them to another page for processing, albeit in a different CMS.

Todd  
[https://squinkd.us](https://squinkd.us)  
[https://xiiro.com](https://xiiro.com)

* * *

freewaytalk mailing list  
email@hidden  
Update your subscriptions at:  
[http://freewaytalk.net/person/options](http://freewaytalk.net/person/options)

---

<div class="post-metadata">

**Author:** ![davedesigner](https://discourse.softpress.com/user_avatar/discourse.softpress.com/davedesigner/32/61_2.png) [@davedesigner](https://discourse.softpress.com/u/davedesigner)\
**Post date:** [February 26, 2015, 10:51am UTC](https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805/3 "2015-02-26T10:51:53Z")

</div>

Thanks Todd,

Did you find anything?

–

David Owen

> On 24 Feb 2015, at 17:36, Todd [email@hidden](mailto:email@hidden) wrote:
> 
> I had to do something vaguely similar with Events a few years ago for a now defunct site. I can’t recall specifics at this point but I’ll see if I still have the code from that job lying around. No promises.
> 
> Although the syntax is different this feels kind of similar to how I filter terms by passing them to another page for processing, albeit in a different CMS.
> 
> Todd  
> [https://squinkd.us](https://squinkd.us)  
> [https://xiiro.com](https://xiiro.com)
> 
> * * *
> 
> freewaytalk mailing list  
> email@hidden  
> Update your subscriptions at:  
> [http://freewaytalk.net/person/options](http://freewaytalk.net/person/options)

* * *

freewaytalk mailing list  
email@hidden  
Update your subscriptions at:  
[http://freewaytalk.net/person/options](http://freewaytalk.net/person/options)

---

<div class="post-metadata">

**Author:** ![davedesigner](https://discourse.softpress.com/user_avatar/discourse.softpress.com/davedesigner/32/61_2.png) [@davedesigner](https://discourse.softpress.com/u/davedesigner)\
**Post date:** [April 24, 2015, 5:38pm UTC](https://discourse.softpress.com/t/perch-passing-variables-into-templates/21805/4 "2015-04-24T17:38:32Z")

</div>

Sorry I should have updated this in case anyone else needs it…

You need the “true” to make it work which is where I was tripping up.

```auto
<?php

// get perch stuff in my php variable to use elsewhere

$myvar = perch_content_custom(‘My Region', array(
		 'page' => ‘/page.php',
               'template' => template.html',
), true); 

echo $myvar;

?>

```

Which means you can output any or all the input fields you need for further processing in your php app. Leaving Perch to do most of the heavy lifting of collecting and sorting information. Lovely!

–

David Owen

> On 24 Feb 2015, at 15:50, David Owen [email@hidden](mailto:email@hidden) wrote:
> 
> I’m hoping someone here has worked with Perch and with a more php dev background help me get my head round a Perch problem.

* * *

freewaytalk mailing list  
email@hidden  
Update your subscriptions at:  
[http://freewaytalk.net/person/options](http://freewaytalk.net/person/options)
