We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem, Runway

Variables not passed into Templates 2.8.2

Drew, I have been at this for hours and absolutely variables are not being passed into templates.

PerchSystem::get_vars()

shows the variables which are populated through routes

Array ( [url_0] => /catalog/200 [url_catID] => 200 [url_1] => 200 [perch_page_path] => /catalog [lang] => en )

and

perch_get('catID') // outputs 200

works a charm... but the variables are not coming into templates...

heres the perch:showall

ID  Value
perch_page_path /perch/core/apps/content/edit/index.php
_id 4
text    test
_title  test
itemRowID   28
itemID  4
regionID    15
pageID  7
itemRev 2
itemOrder   1000
itemJSON    {"_id":"4","text":"test","_title":"test"}
itemSearch  test
itemUpdated 2015-03-03 21:40:14
itemUpdatedBy   1
perch_item_first    true
perch_item_last true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  
perch_item_count    1

I have been using perch_content_custom()

Robert Ketter

Robert Ketter 103 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's certainly working in my tests here, Robert. Can you give a more concrete example?

All Files: https://github.com/robertketter/perch_template_var_test.git

Template: Standard out of box article.html

<h2><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h2>
<p class="date"><perch:content id="date" type="date" label="Date" format="%d %B %Y" required="true" /></p>

<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" required="true" />

<p class="vcard">
    © <perch:content id="date" type="date" label="Date" format="Y" />

    <span class="fn n">
        <perch:content id="author_given_name" type="text" label="Author given name" />
        <perch:content id="author_family_name" type="text" label="Author family name" /> 
    </span>  
</p>

<perch:after>
  <perch:if exists="paging">
    <div class="paging">
      Page <perch:content id="current_page" type="hidden" /> of <perch:content id="number_of_pages" type="hidden" />
      <perch:if exists="not_first_page">
        <a href="<perch:content id="prev_url" type="hidden" encode="false" />">Previous</a>
      </perch:if>
      <perch:if exists="not_last_page">
        <a href="<perch:content id="next_url" type="hidden" encode="false" />">Next</a>
      </perch:if>
    </div>
  </perch:if>
</perch:after>
<perch:showall />

Page: template_var_test.php

<?php

    perch_content_create('News', array(
        'template' => 'article.html',
        'multiple' => true,
        'edit-mode' => 'listdetail',
        'sort' => 'date',
        'sort-order' => 'DESC',
    ));

    PerchSystem::set_vars(array(
        'colour'=>'red',
        'fruit'=>'apple',
        'season'=>'winter'
    ));

?><!doctype HTML>
<html>
<head>
</head>
<body>
<?php perch_content_custom('News'); ?>

<p><?php print_r(PerchSystem::get_vars()); ?></p>
</body>
</html>

Perch 2.8.2 Output

Test 1

04 March 2015

Hello World

© 2015 Robert Ketter

ID  Value
perch_page_path /perch/core/apps/content/edit/index.php
_id 5
heading Test 1
_title  Test 1
date    2015-03-04
body    
Hello World

author_given_name   Robert
author_family_name  Ketter
itemRowID   30
itemID  5
regionID    17
pageID  9
itemRev 1
itemOrder   1000
itemJSON    {"_id":"5","heading":"Test 1","_title":"Test 1","date":"2015-03-04","body":{"raw":"Hello{...}
itemSearch  Test 1 Wednesday 04 March 2015 Hello World Robert Ketter
itemUpdated 2015-03-04 06:08:43
itemUpdatedBy   1
perch_item_first    true
perch_item_last true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  
perch_item_count    1
Array ( [colour] => red [fruit] => apple [season] => winter [perch_page_path] => /test )

Debug Message
SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC
Using master page: \templates\pages\template_var_test.php
Page arguments:
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/test' OR regionPage='*' ORDER BY regionPage DESC
Time: 0.0614
Memory: 2.5697

As you can see, The variables are there...

Array ( [colour] => red [fruit] => apple [season] => winter [perch_page_path] => /test )

but the variables are not passed in... then finally at the end of the page you see the output of get_vars() (just above debug output) and all the variables are still there.

Somehow this has worked its way down to 3rd page. Hoping it doesn't get buried and forgotten. :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Not forgotten, just needs deeper delving into, as it's all working for me at the moment.

Drew, Could you please provide me a simple page (template) that is working on your system, that I can plug into mine and see if it works here.

I must be doing something wrong somewhere cause in the past I have had this working, but now I don't seem to have it working on development server (perch or runway) or working in my real world server.

I know your busy and I take value in any time you have to help me and the many others.

Thanks man,

Robert

Drew McLellan

Drew McLellan 2638 points
Perch Support

Here's what I'm using:

<?php
    perch_content_create('Region1', [
        'template'=>'test/vars.html',
        ]);

    perch_content_custom('Region1', []);

And my vars.html template is:

<perch:content id="test" label="Test" type="test" />
<perch:showall />

Drew, I could totally shoot myself right about now... The problem was so simple and your code made it VERY clear...

I had forgotten the array() in my perch_content_custom()

mine:

perch_content_custom('News');

yours:

perch_content_custom('Region1', []);

my original code is working flawlessly now... with the missing second argument in place...

Thanks so much...

Drew McLellan

Drew McLellan 2638 points
Perch Support

No problem - a simple mistake is the best outcome as far as I'm concerned! :)