Forum
template variables not passing
I am trying to send a custom variable to template page, below is my code.
pages/detail.php
PerchSystem::set_var('custom_cat', 'collection');
perch_content_custom('Collection', array(
'page' => '/collection',
'template' => 'collection/collections_detail.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
print_r(PerchSystem::get_vars());
content/collection/collections_detail.html page content
<perch:content id="custom_cat" />
I don't get any value in template. I am however getting value in print_r
I made sure "custom_cat" id was unique in the template.
What does
<perch:showall />
output in the template?<perch:showall /> shows "custom_cat" and the value correctly.
Ok, great. So how is the output wrong?
When i try to output "custom_cat" value on the page. I get empty. below is the code I am using to print
Can we see your template? If it's there in
showall
then it should be available.Are you using repeaters or blocks and not bringing the top level variable into scope?
Here is my template code
It's scoping.
Use
scope-parent="true"
on yourperch:categories
tag and then reference it withparent.custom_cat
You are probably not going to like me and the reply... that didn't work. here is the template code
I think you'll need to use a
perch:category
tag in that context.showall
will help with this again.I finally got it to work. Here is the solution
<perch:content id="custom_cat" /> does not work if i am within category loop
Thanks Drew, perch:showall was very helpful
Yes, that's what I was saying! Glad you got it working.