Forum
How do I achieve this?
I cant quite figure out how to achieve the following using conditionals:
The editor of a page is presented with a choice
a) display the default testimonial quote in the region (which will be hard coded in).
b) Choose to add a new testimonial for the region instead, to replace the default one.
Please can someone give me some pointers? Are conditionals the best way?
Something like this?
Thanks Shane.
Well, thats what I thought, but its not working for me. Any idea why? This is what I have...
Seems to me the first line should be
<perch:if exists="custom-testimonial">
Your id attribute cannot contain an underscore: https://docs.grabaperch.com/templates/attributes/id/
I believe that Rachel meant that your id attribute cannot contain a hyphen.
Thanks for the input guys. All noted, but still not working. This is what I have right now:
However, the problem is that if I add a custom testimonial, the default one appears instead! And I cant leave the custom testimonial text box and author blank, because Perch wont let me save text areas with no content.
Is there something about the logic here that Im not getting?
It looks like you don't have a region ID that matches the <perch:if> ID "CustomTestimonial". Change the ID in <perch:if> to one of your region IDs ("quote" or "author"), or change a region ID to "CustomTestimonial".
Also, Perch won't let you save a blank region only if it contains
required="true"
Ok but if I have 'quote' and 'author' as regions, how do I add a region id to the Blockquote that wraps them? Does a region id have to be preceeded by '<perch:content...>'? if so, how do I close it? Sorry if Im not making sense!
<perch:content...> IS a region. <perch:if> is only aware of Perch content regions. Perch isn't aware of the IDs of your HTML elements (like blockquote). So, you need to match the ID of <perch:if> to one of your content regions, i.e. 'quote' or 'author'. The blockquote ID isn't needed.
Thanks, I understand that Shane, where I'm struggling is that I have 2 regions - quote and author, but I need to wrap them in another region that I can then give an id to, so that the 'if' statement can target the wrapper. How do I create a region that I can use as a wrapper, since regions don't seem to have closing tags?
Chris, I'm not sure I'm following your logic or definition of "region". If you change your first line to
<perch:if exists="quote">
, I'm pretty sure this will work just the way you want.Boom! And so it does work nicely.
Sorry - I was assuming that the if statement would'nt work because there were 2 regions in the wrapper that I want to be conditional together.
Thanks very much for your help Shane, and your patience :)
Happy to help!