Forum

Thread tagged as: Question, Problem, Configuration

How do you pass a category list as php variable into a template

I can add my category list template as a php variable...

<?php 
  $catherobtns = perch_categories(array(
        'template'   => 'category_tags_hero.html',
        'set' => 'services',
  'include-parent' => true,
  ), true); 

echo($catherobtns);
?>

OK Fine which outputs my template of cat buttons...

<ul class="ProdCatlist">
<li class="ProdCatTag">
    <a href="/category.php?cat=services/private-client/" class="heroBtn">Private Client</a>
</li>
<li class="ProdCatTag">
    <a href="/category.php?cat=services/property/" class="heroBtn">Property</a>
</li>
<li class="ProdCatTag">
    <a href="/category.php?cat=services/family-law/" class="heroBtn">Family Law</a>
</li>
</ul>

But how can I add $catherobtns into another template on the page? This template is a slideshow where I need the catherobtns to appear in a repeater

<perch:help>
    <p>This section is to edit the slideshow panel with a maximum of 3 panels.</p>
</perch:help>

<section class="hero">
    <div class="hero-center slick">

        <perch:repeater id="slideshow" label="Slideshow" max="3">
            <div class="slidepane panel">
                    <div class="panelpic" style="background-image: url(<perch:content type="image" id="image1" label="Panel Image" width="960" help="Add a primary image at least 960px wide" bucket="slideshow" order="2" />)">
                    <div class="herotextbox heroBtnwrap">
                        <p class="f-fp">Select from the core services we provide...</p>

                        <!---- buttons here ---->
                        <p><perch:content id="catherobtns" /></p>
                        <!---- buttons here ---->

                    </div>
                </div>
                <div class="sidepanel">
                    <h2><perch:content id="cat" type="text" label="Category Name" required="true" words="3" size="m" help="Max 3 words" order="3" order="1" /></h2>
                    <p><perch:content type="textarea" id="textarea" label="Text" size="s" words="25" help="Enter a short summary - limited to 25 words" append="..." required="true" order="4" count="words" /></p>
                </div>  
            </div>
        </perch:repeater>           

    </div>
</section>

The perch documentation lists perch_content_custom and I need perch_categories?

PerchSystem::set_var('lang', 'en');
perch_content_custom('My region', [
    'template'=>'template.html'
]);

For example, the following gets me nowhere...

<?php 
PerchSystem::set_var('catherobtns', $catherobtns);
perch_categories(array(
        'template'   => 'category_tags_hero.html',
        'set' => 'services',
  'include-parent' => true,
  ), true); 
?>

And advice for this?

David Owen

David Owen 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

By "gets me nowhere" what do you mean? What behaviour are you seeing? What does showall output?

Not positive, but I think you need to bring catherobtns into scope for the repeater: <perch:repeater id="slideshow" label="Slideshow" max="3" scope-parent="true">

Then use <perch:content id="parent.catherobtns" type="hidden" encode="false" />

Thanks - that got it!