Forum
Is it possible to check a category is present in two templates?
Hi
I would like to check which category is selected from a content template on a page and then display a template based on a different shared content region which has the same category selected.
Is this possible?
Thanks
Neil
Hello Neil,
So you have region (A) on a page and would like to check whether a specific category is selected in it? Yes, this can be done.
I'm not sure I quite understand this part of your question. Do you only want to display the shared region if both the shared region and region (A) have a specific category selected?
Hi Hussein
Thanks for your reply.
I have a page template which creates a content region automatically on adding a new page. Within the the content region there is a category field. The same category set is used on a shared region. I would like to check which category has been selected in the content region associated with that page and then display associated items from the shared region on the page.
Hopefully this makes sense.
Thanks
Neil
You can check what category has been selected in PHP by using
perch_content_custom
with theskip-template
option:Alternatively if you are more comfortable working with templates than PHP, you can create a separate template to perform the check:
Make sure the template has no unnecessary white space. Return the template instead of echoing it:
If you want to compare the catPath inside the shared region template, you can pass it as a variable:
Or if your shared region is a multi-item region and can be filtered with the category option:
Thanks Hussein for your help on this one.
Thanks
Neil