Forum

Thread tagged as: Question, Blog

Passing variable into Perch Blog template

Hi,

I'm trying to pass a variable into a blog template but can't seem to get it working.

I am using the following in my blog/index.php file

<?php
    PerchSystem::set_var('sectionSlug', 'en');
    perch_blog_categories(array(
        'template' => 'category_link.html',
    ));
?>

and then I have the following in my category_link.html template

<perch:before>
<h4>Categories</h4>
<ul class="blog-nav">
</perch:before>
    <li><a href="/<perch:blog id="sectionSlug" />/blog/archive/category/<perch:category id="catSlug" />"><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a></li>
<perch:after></ul></perch:after>

The output from the template doesn't show anything where I'm expecting the sectionSlug to display.

Am I doing something wrong or missing something at all?

Thanks in advance for any help.

Simon Kelly

Simon Kelly 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try perch:category instead of perch:blog for your tag.

That's perfect! Thanks for your help, Drew.