Forum

Thread tagged as: Suggestions

Expose parent category slug?

Hi,

When a category has subcategories, is there a way to expose the parent category as an ID?

In a category template perch:showall reveals these two IDs

  • catSlug = automation
  • catPath = solutions-en/automation-and-materials-handling/automation/

automation is a subcategory of automation-and-materials-handling

But there's no unique ID for the parent category?

Something like this would be useful;

  • catParentSlug = automation-and-materials-handling

I'm creating a sitemap template and it'd be really useful if I could make use of the parent category.

Typically I'd hardcode the path up to the catSlug, but the structure of one my websites is setup a bit different.

My category sitemap template needs to be structured like this:

<url>
<loc>https://website.com/<perch:category id="catParentSlug">/solutions/<perch:category id="catSlug"></loc>
</url>

Could this be considered for a future release of Perch/Runway?

Stephen Meehan

Stephen Meehan 4 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can do that using a template filter. Use explode on the path using / as the delimiter to get an array of all the sections of the path.