1

In short: I need to display embedded templates based on whether they are selected by checkbox on the publish page, but my code doesn't work if more than 1 is checked.

I tried using the code below to check for whether a checkbox was checked and display the template if it was. This works, unless more than one is checked off, then none display because the statement no longer validates as true.

I have one full-page template shared by 2 pages. I have one page that requires Rides, and the other requires all 3 templates.

The name of my checkbox field is choose_entries, and the options are "Rides" "Gear" "Groups".

{exp:channel:entries channel="pages" limit="1" url_title="{segment_1}"}
    {if choose_entries == "Rides"}
            <h2 class="section-title">Rides<span class="green"></span></h2>
            {embed="views/.rides"}
            <img src="content/img/bike.png" />
    {/if}
    {if choose_entries == "Gear"}
            <h2 class="section-title">Gear<span class="orange"></span></h2>
            {embed="views/.gear"}
    {/if}
    {if choose_entries == "Groups"}
            <h2 class="section-title">Groups<span class="blue"></span></h2>
            {embed="views/.groups"}
    {/if}
{/exp:channel:entries}

I know there is probably a way to do it with php (but I don't write php), I would like to avoid that if possible. I was unable to find the correct php syntax to get an "if contains" type statement to work.

  • So can a single entry have more than one item ticked in the checkbox? Or do you mean that if more than one entry has 'Rides' ticked for instance? – Ian Apr 22 '13 at 21:47
  • 1 page can have more than 1 entry checkbox checked to display embedded sections, i.e. the page San Diego can have "Rides" and "Gear" checked to display those embedded templates on the page. – Alexa L Apr 22 '13 at 23:28
0

Don't even attempt to do something like this with the native checkboxes, they're really substandard. Use pixel and tonic's field pack instead and you'll have no problems:

http://devot-ee.com/add-ons/pt-field-pack

| improve this answer | |
  • I was using that but hadn't been able to get the syntax working. Turns out I was missing an end quotation mark. Thank you! – Alexa L Apr 22 '13 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.