Forum
Show regions based on page attribute
Hi Guys,
So I've set up the following in my page assets template:
<perch:pages id="is_landing_page" type="checkbox" label="Make landing page" help="Warning: Only enable this on landing pages" value="true" suppress="true"/>
Then on my content_sections.html template I have tried to do this:
<section class="landing <perch:if id="is_landing_page" value="false">collapsed</perch:if>">
However it doesn't seem to ever register as true. I've tried perch:showall and it doesn't seem to have any ability to see what the page attributes are. Is there a way to reference them?
What happens if you do this:
Same thing unfortunately.
How are you displaying the
content_sections.html
template?Like this:
Is there such a thing as an 'if perch_page_attribute' statement? I suspect that although I've set 'is_landing_page' in page attributes, there is nothing to set that variable on the template itself.
Yoo could something like this in PHP:
Ah I didn't realise I could make php templates. I thought they had to be html only. Thanks, I'll try it out :)
Hmm.. it seems they do have to be html. I can see the php template in the templates list but it wont allow me to select it.
PHP needs to be on the page not in the template. Perch template tags go in the template.
I can possibly achieve what I wanted in the page by switching templates in the page (using the conditional above), however I wanted to avoid repeating code, which I'd have to do if I used two templates.
Is there no way to check the existence of page attributes using template tags?
Would it be possible in your case to achieve what you want trough css selection like this:
the conditional class is given in the page-template with the if-statement i posted above. Like this:
This may be the answer I was looking for.
https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/
I'll try it and post back to let you know if it worked.
Yes but I don't just want to change the page, I also want to prevent the fields appearing in the editor (I don't want the client to be confused and try to add information for a section which won't appear on some pages)
I'm really unclear as to what you are trying to do I'm afraid.
Can you explain what end result you are trying to achieve?
Ah right, I've just seen your reply to Manuel. That's not possible, the templates don't control what is seen in the editor. Use help text to describe what your user needs to do.
I think you should go with to separate content templates then.
Ah I see. Ok fair enough. Thanks anyway guys :)