0

I have a page where I am allowing the client to choose which channel entries are displayed on the page, which is controlled by a field with checkboxes on the publish page.

If rides is checked, I need to display entries from the ride channel. If rides and gear is checked, I need to display entries from both.

I have never had to use checkboxes as a field before, and am unsure how to display content only if a specific checkbox is checked. The values of my checkboxes are:

Rides

Gear

Group

The name of my custom checkbox field is choose_entries

{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'm pretty sure my conditionals are incorrect at present, I need some help getting them to work properly. Thank you!

And in case it's needed, here is an example of one of the embedded templates, but they display properly on their own.

{exp:channel:entries channel="rides" orderby="date" dynamic="no" sort="asc" limit="5" show_future_entries="yes"}
<article class="rides left">
<img src="{ride_img:excerpt}" alt="{title}, ${event:price}" />
<div class="content">
    <h2>{title}</h2>
    <p class="lead">${event:price}</p>
    <p>{ride_excerpt}</p>
    {if "{event:can_purchase}" == "y"}
        <p class="read-more"><a class="blue" href="{path=checkout/quantity/{event:id}}">Book now</a></p>
        {if:else}
        <p><strong>Tickets are not available</strong></p>
        {/if}
</div>
</article>  
{/exp:channel:entries}

Note: I am using Pages and Better Pages to make use of a template across multiple pages, if that complicates matters any.

1
  • The structure of the site is basically: 1 template used by 2 page entries (currently) that is wrapped in a channel entries tag with limit of 1 from the "Pages" channel There is a checkbox field with 3 options "Rides" "Gear" "Groups" that determines what entries will be embedded on the page. The problem: 1 of the page entries is correctly displaying the "Rides" entries checked on it's publish page. The other page entry has all 3 checked and is displaying none. Is this maybe an issue with the conditional statements?
    – Alexa L
    Apr 19, 2013 at 16:59

1 Answer 1

3

The problem in your code stems from the placement of your conditional. Because you haven't started with a channel:entries call EE has no idea what choose_entries is. But you cant put a channel:entries call within another (nested) so you would need to do something like this.

{exp:channel:entries (any relevant parameters to pull the correct entry)}
  {if choose_entries == "Rides"}
    {embed="includes/.rides"}
  {/if}
  {if choose_entries == "Gear"}
    {embed="includes/.gear"}
  {/if}
  {if choose_entries == "Groups"}
    {embed="includes/.groups"}
  {/if}
{/exp:channel:entries}

in the embed calls if you are not familiar with them 'includes' is the template group and '.rides' is the template. I like to use a . before any template i dont want to be accessible via the web. On the embeded templates just add your chunk of specific code as above ie.

Rides
        {exp:channel:entries channel="rides" orderby="date" sort="asc" limit="5" show_future_entries="yes"}
                    <article class="rides left">
                        <img src="{ride_image:excerpt}" alt="{title}, ${ride_price}" />
                        <div class="content">
                                <h2>{title}</h2>
                                <p class="lead">${ride_price}</p>
                                <p>{ride_excerpt}</p>
                                <p class="read-more"><a class="blue" href="/san-diego">Learn more about this ride &raquo;</a></p>
                        </div>
                    </article>  
        {/exp:channel:entries}
                    <img src="content/img/bike.png" />

Hope that makes sense. There is at least one other way you could do this by passing info to a single embedded template but this way is the easiest to explain.

2
  • I should have clarified that my entire template is wrapped in a channel entries tag to pull in the page content. I changed my embed template to reflect your first code block, however only rides is shown on 1 of the pages, when both pages have it checked. The 2nd page has all 3 checked, but displays none of them.
    – Alexa L
    Apr 19, 2013 at 16:57
  • I just tried variations of checkboxes, and it seems if more than 1 is checked, the {if choose_entries == "Rides"} etc doesn't validate as true, because it is equal to more than 1 value at the point. I am unsure how to go about accommodating this.
    – Alexa L
    Apr 19, 2013 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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