Forum

Thread tagged as: Question, Problem

Skip-template returning id of categories instead of category path

Hi,

I'm trying to filter perch_content_custom by category based on the category of the current item to show related content. I want to get the category path from the skip-template array. The problem is that I only get ids instead of category path.

$workResult = perch_content_custom('Case studies', array(
    'skip-template' => true,
));

perch_content_custom('Case studies', array(
    'template' => 'our-work/work_listing_basic.html',
    'category' => 'sector/financial-services/',
    'count' => 3
));
Array
(
    [0] => Array (
        [_id] => 63
        [project_name] => Pockets
        [_title] => Pockets
        [slug] => pockets
        [clients] => Array
            (
                [0] => 10
            )

        [sector] => Array
            (
                [0] => 38
            )
    )
)

My template looks like this:

<perch:content id="project_name" type="text" label="Project name" title="true" />
<perch:content id="slug" type="slug" for="project_name" label="Url" editable="true" indelible="true" />

<perch:categories id="clients" label="Client" set="clients" required="true">
    <perch:category id="catTitle" type="text" />
</perch:categories>

<perch:categories id="sector" label="Sector" set="sector" required="true">
    <perch:category id="catTitle" type="text" />
</perch:categories>

<perch:content id="project_description" type="textarea" label="Project description" size="s" />

<perch:blocks>
    <perch:template path="content/blocks/text_content.html" />
</perch:blocks>

<perch:content id="casestudy" type="image" label="Project cover" width="1280" height="690" crop="true" quality="75" bucket="case-studies" required="true" />

<perch:content id="casestudy" type="image" label="Project cover" width="500" height="500" crop="true" quality="75" bucket="case-studies" />

<perch:content id="in_slideshow" type="checkbox" label="Add to the main slider?" />

The very weird part is that I do get the category path when I do the same thing for another region and after checking, the category templates look alike. I don't seem doing something very different from one region to the other.

Here's my debug from the admin and below the debug from the particular page where I get the skip-template from:

Perch: 2.8.14, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.14), assets (2.8.14), categories (2.8.14), jw_activity_log (1.0.0), perch_blog (4.6), perch_backup (1.2)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog' );
PERCH_LOGINPATH: /perch
PERCH_PATH: /something/perch
PERCH_CORE: /something/perch/core
PERCH_RESFILEPATH: /something/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
Resource folder writeable: Yes
HTTP_HOST: aleph-labs.local:8888
DOCUMENT_ROOT: /something
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php




Debug Message
SELECT * FROM perch2_pages WHERE pagePath='/our-work.php' LIMIT 1
Using template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/seo.html
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/our-work.php' OR regionPage='*' ORDER BY regionPage DESC
SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/our-work.php' LIMIT 1
SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002', '000')
Using template: /templates/navigation/item.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Case studies' AND (regionPage='/our-work.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=32 AND idx.itemRev=122)) AND ((idx.indexKey='slug' AND idx.indexValue='pockets')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Using template: /templates/content/our-work/work_detail.html
Using sub-template: /templates/content/header/interactions.html
Using sub-template: /templates/content/blocks/text_content.html
SELECT idx.itemID FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID WHERE ((idx.regionID=32 AND idx.itemRev=122)) AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'sector/financial-services/%'))
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=32 AND idx.itemRev=122)) AND idx.itemID IN ('67', '69', '65', '63') AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 3
Using template: /templates/content/our-work/work_listing_basic.html
SELECT * FROM perch2_categories ORDER BY catTreePosition ASC

Any help would be greatly appreciated. Cheers!

Robin Pick

Robin Pick 5 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That's currently what is returned, yes. We plan to improve it in a future release.

Hi Drew,

What's weird is that I do get the category path for another region:

$test = perch_content_custom('Offices', array(
       'skip-template' => true,
       'template' => 'offices/office_detail.html'
));

print_r($test);

Gives me:

Array
(
    [0] => Array
        (
            [_id] => 78
            [offices] => Array
                (
                    [0] => offices/singapore/
                )

            [_page] => /locations.php
            [_pageID] => 7
            [_sortvalue] => 1000
        )
)

The template for this region is:

<perch:categories id="offices" label="Office" set="offices" required="true">
       <perch:category id="catTitle" type="text" />
</perch:categories>
<perch:content id="office_title" type="text" label="Titre" urlify="true" />
<perch:content id="slug" type="slug" for="office_title" />

<perch:content id="location_initials" type="text" label="Short-hand" suppress="true" title="true" />
<perch:content id="text" type="textarea" label="Office address" markdown="true" size="s" />
<perch:repeater id="office_emails" label="Email address">
       <perch:content id="email" type="text" label="Email address" />
       <perch:content id="email" type="text" />
</perch:repeater>
<perch:content id="country_banner" type="image" label="Country banner" suppress="true" />
<perch:blocks>
       <perch:template path="content/blocks/text_content.html" />
</perch:blocks>
<perch:content id="is_visible" type="checkbox" label="Should the office be visible?" />

I've used the exact same implementation for another site where I get the category path of the current item to pass it to category with skip-template to filter other items from the same cat.

If I'm not mistaken, the feature was added as part of Perch 2.7.6 (https://grabaperch.com/update/v2-7-6): "adds category paths to skip-template output".

Cheers,

Drew McLellan

Drew McLellan 2638 points
Perch Support

Oh, I'm ahead of myself then. Are you setting the template option? That might be the difference.

Hi Drew,

I'm not sure what you mean by template option. Do you mean the category set options?

Drew McLellan

Drew McLellan 2638 points
Perch Support

This gives you IDs:

$workResult = perch_content_custom('Case studies', array(
    'skip-template' => true,
));

This gives you paths:

$test = perch_content_custom('Offices', array(
       'skip-template' => true,
       'template' => 'offices/office_detail.html'
));

One key difference is the use of the template option - that's what I mean.

Thanks Drew.

I had the template already set with perch_content_custom but you did put me in the track: my template was missing <perch:categories>. It was there in the master template but it was missing for the template referenced in perch_content_custom.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Perfect.