Forum
Allow user to choose 'featured' image for each page
I would like to enable a page option allowing the user to set a feature image, similar to what they do in Wordpress. I have set this up as a page attribute, however Perch returns the code at the point the attribute is set.
Is it possible to set up a 'hidden' page image attribute and call it into a template afterward if required?
Currently I'm including this code in the default attributes template:
<perch:pages id="pageImage" label="Main Image For Page" type="image" divider-before="Set Image for Page" />
Perch outputs the image path where this appears (currently in the head). Could I set it not to output the code? and use the attribute elsewhere?
You can return a layout by passing in true to the perch_layout function, as shown in the docs: https://docs.grabaperch.com/docs/layouts/displaying/
Pretty much all of the Perch functions work like this, if you pass true as the last param you can get the data to work with.
Thanks Rachel, Getting the data wasn't the issue, I've trawled the docs before submitting the question and can't see what I need.
What I'm looking to do is allow the user to set the page option, but not have perch return it in the code (I wish to call it in later).
Have a look at: https://perch.sixtillnine.co.uk
As you can see I'm playing with setting up a menu that will feature images and text. The images in the menu are being drawn in from the page details (attributes) of the respective pages returned for the menu.
However as you can also see Perch is returning the image path in the head, where I set up the attribute.
Is this possible to create an attribute to appear in the page details without it appearing on the page?
If you use
suppress="true"
in the head attribute template it will not output to the page.Thanks Simon! Spot on. Much appreciated.
Hello Simon, Sorry to bother you again...
Is here a way to unsuppress attribute, to call it back into a page?
I wish to hide it in the head, but display it in the body. I have achieved this with creating a different template (duplicated and removed the suppress code) - but it feels like I'm doing it wrong.
Alternatively, is there a way of hiding templates from the 'Attribute Template' drop down menu in the 'Page Options' tab of the editor?
You're right Tony... Duplicate the tag but remove the
suppress="true"