Forum

Thread tagged as: Problem

Categories template tag in perch:before tag

Hi,

I've created a category set and called it 'Projects'. I've then created a multi region content item, also called projects and in the template, I've used something like the below:

<perch:before>
<div class="filter-bar mt40">
    <perch:categories id="ProjectCategory" set="projects">
        <perch:before>
            <ul>
        </perch:before>
                <li>
                    <a href="?category=<perch:category id="catSlug" />"><perch:category id="catTitle" /></a>
                </li>
        <perch:after>
            </ul>
        </perch:after>
    </perch:categories>
</div>
<div class="latest-projects mb40">
</perch:before>
    <a href="/project/<perch:content id="slug" type="slug" for="Title" />" class="latest-project">
        <div class="latest-project--details">
            <h2><perch:content id="Title" type="text" label="Title" /></h2>
            <span class="lastest-project--subtitle"><perch:content id="SubTitle" type="text" label="Subtitle" /></span>
            <span class="latest-project--view" href="#">View poject</span>
        </div>
        <img class="latest-project--image" src="<perch:content id="MainImage" type="image" width="640" height="400" crop="true" />" alt="<perch:content id="Title" type="text" label="Title" />">
    </a>
<perch:after>
</div>
</perch:after>

So, I'd like to output the categories from that set in the <perch:before> tag of that template, but it's not working as expected. If I use it in perch before, it will only output the categories applied to the first item in the multi region content item. If I move the categories tag to the <perch:after> tag, it'll display the cats that are applied to the last item. It doesn't output all the categories in the set.

Diagnostic below:

Perch: 2.8.8, PHP: 5.5.1, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4 $, with PDO
Server OS: WINNT, apache2handler
Installed apps: content (2.8.8), assets (2.8.8), categories (2.8.8)
App runtimes: <?php $apps_list = array( 'content', 'categories', );
PERCH_LOGINPATH: /perch
PERCH_PATH: E:\Vital\Local Projects\Evolve\trunk\Evolve\perch
PERCH_CORE: E:\Vital\Local Projects\Evolve\trunk\Evolve\perch\core
PERCH_RESFILEPATH: E:\Vital\Local Projects\Evolve\trunk\Evolve\perch\resources
Image manipulation: GD
PHP limits: Max upload 2M, Max POST 8M, Memory: 128M, Total max file upload: 2M
Resource folder writeable: Yes
HTTP_HOST: evolve.dev:81
DOCUMENT_ROOT: E:/Vital/Local Projects/Evolve/trunk/Evolve
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

For now, I'm simply using the below code to output the projects:

perch_content_custom('Projects', array(
                'page'      => '/project.php',
                'template'  => 'projects.html'
            ));
Jon Young

Jon Young 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's how it works. Before is processed before the first item and After is processed after the last.

What were you aiming for?

Oh ok. I was hoping to list all the categories in a set in the same template as the project listing. If you imagine an isotope style listing of projects with a filter at the top - the cats being the filter.

I thought the <categories> tag might be processed separately to everything else, much in the same way as pagination is?

If it cant be done, not to worry. I'll just output the categories in a separate template. Thanks for your reply anyway.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not really sure what an isotope style listing is, so I'm not sure how to help.

Sorry, isotope is just a javascript plugin that arranges elements nicely on a page, but it's irrelevant really, all I wanted was all the categories from a set to output in the same template that I've used for the client projects. It would have been nice to be able to put all the code in one template, but I've just used two separate templates now :)