0

Channels and Fields Summary:

  • Tours channel - stores a list of all Vacations the site offers
    • tour_specials field - a Playa field, linked to the Specials channel indicating which Special Offers apply to this tour
    • tour_show_specials_banner field - a Switch to determine whether to show a special offer banner against this entry, if the tour_specials field has any entries
  • Specials channel - list of Special Offers that can apply to multiple tours
  • Promotions channel - stores lists of tours our partners want to promote. Though it sounds similar to Specials, it is distinct from a business perspective.
    • promotion_tours field - a Playa field that stores multiple tours channel entries, indicating which tours are linked to a promotion

The Problem:

  • I have created a Promotions page that gets a Promotion, and lists all tours associated with the promotion from the promotion_tours Playa field
  • The listing of tours in the Promotion also needs to check whether a tour has a Special Offer running, by looking at the tour_specials field in the tours entry to see if any Specials apply
  • However, all the various code blocks below WILL NOT ever evaluate to true, in the event a tour listed has a Special associated with it

The Code:

Here's the master code block that outputs all Playa entries from the promotion_tours field (all tours associated with the promotion):

{promotion_tours dynamic_parameters="orderby|sort|limit" orderby="title" sort="asc" limit="10" disable="categories|category_fields|member_data" var_prefix="promotions" paginate="bottom"}

    <a href="{promotions:site_url}/{promotions:url_title}">
        <img src="{promotions:tour_gallery limit="1"}{promotions:tour_photo_file:thumbnail}{/promotions:tour_gallery}"/>

        <!-- PROBLEM STARTS HERE -->
        <!-- If we want to show a Special Offer banner... -->
        {if promotions:tour_show_specials_banner}

            <!-- Then check if there are any linked Specials -->
            {if {promotions:tour_specials:total_children} > 0}
                    <img class="special-offer-banner" src="{site_url}images/site/special-offer.png" alt="Special Offer" title="Special Offer" />
            {/if}

        {/if}
    </a>

{/promotion_tours}

I am using a var_prefix to allow my Playa entries to be paginated (see here for an explanation).

You can see where the problem starts is with {if promotions:tour_show_specials_banner}. That statement NEVER evaluates as TRUE, even when I know it should do. The following situations NEVER output anything:

{if promotions:tour_show_specials_banner}
{if tour_show_specials_banner}
{if {promotions:tour_show_specials_banner} == "y"}
{if promotions:tour_show_specials_banner == "y"}
{if {tour_show_specials_banner} == "y"}

I know some are syntactically incorrect but I'm getting to my wits end here...

HOWEVER, if I just output {promotions:tour_show_specials_banner} in my HTML, it outputs y in to the content! Which must evaluate as TRUE!

I'm seriously stumped. Any ideas?

1 Answer 1

2

There are some issues in EE 2.9 with conditionals on prefixed variables and variable modifiers which I don't totally grok. (See bug report here for some discussion.)

But the moral is, try this:

{if '{promotions:tour_show_specials_banner}' == 'y'}
1
  • Brilliant, thank you so much Derek. I had been tearing my hair out over this. Really appreciate the response, thank you!
    – Jack
    Mar 19, 2015 at 16:10

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.