Go to page content

Retrieving the category of a page

Getting the category from a URL is somewhat involved, but not impossible. This is an example of what you can do with filters.


It is often useful to use a page's category to present it on the page itself or to look up related content.  This guide provides step-by-step instructions for getting a page's category in a template.

I have a page with url of the form /my_category, /my_category/id, or /my_category/id/slug. How can I retrieve the category from the url?


Readers are assumed to be comfortable with template development.


Since category is a direct property of m_rsc we can directly access it:

{% with id.category as my_cat %} 
{% endwith %}


There are no troubleshooting steps available for this guide.  Please provide any you have learned in the comments below or on the Zotonic Users Group.

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.