1

I have a matrix field that has 1 column, which is a playa field.

The playa field is set up to allow the user to choose any open entry within 2 different channels. I need to display code in the template that has a conditional the chooses 2 options based on what channel the selected entry (chosen in the playa field) is from.

In other words: user selects an entry in the playa field. That entry can be from either channel A or channel B. I need conditional code that displays one thing if the selected entry is from channel A, and something different if the selected entry is from channel B.

How do I do that? Thanks!!!

here is my template: Note that I can't get ANY type of conditional statement to work where indicated in the comment, but the 2 conditionals outside the EE channel tag DO work.

<!-- news promos using Matrix & Playa fields -->
{exp:channel:entries channel="home_page" disable="categories|category_fields|member_data|pagination" limit="1" dynamic="off" show_future_entries="yes"}
            <!-- start matrix field -->
            {homepage_news_4items}
                    {!-- start playa field within the matrix --}
                    {hp_news_promo}
                    <li>
                        <em>{entry_date format="%M. %j, %Y"}</em>
                        <div class="text">
                            <!-- need to insert an EE conditional statement on this line to replace the xxxxxxx --><a href="{path='/xxxxxxxx/{url_title}'}">{exp:word_limit total="7"}{news_long_title}{/exp:word_limit}</a>
                        </div>
                    </li>
                    {/hp_news_promo}
                    {!-- end playa field within the matrix --}
            {/homepage_news_4items}
            <!-- end matrix field -->
{/exp:channel:entries}
<!-- /news promos using Matrix & Playa fields -->



{if username == 'rory'}Hi Rory!{/if}

{if segment_2 == 'march14test'}this is the test template{if:else}wrong URL{/if}

----- END TEMPLATE

Here's what I want to insert as a conditional on the line indicated (to replace the whole line):

{if channel_short_name == "industry_news"}{if:else}{/if}{exp:word_limit total="7"}{news_long_title}{/exp:word_limit}


Well, I have concluded that there is no way to use a conditional inside the matrix/playa code, which is a big disappointment. I even tried the trick with the variable prefix, and it didn't work.

2 Answers 2

2

You can use {channel_short_name}:

{if channel_short_name == "channel_a"}
    ...
{if:else}
    ...
{/if}
2
  • Hi Brandon! An honor to be in your presence again. I've been trying to get this to work all morning. I added my template code into the original question above. I cannot get ANY conditional statement at all to work on the line where I indicate. But the conditionals at the end of the EE channel tag do work. I am thinking that there is something about the combination of the matrix & playa fields that makes the conditional fail? Commented Mar 14, 2014 at 17:17
  • Also, I put the code for the conditional that I need at the end of my original question. @brandon_kelly Commented Mar 14, 2014 at 17:21
0

What do you get if you output {channel} in your template for the related fields in your playa loop? Maybe try {playa-field-name:channel} I think you'll get the channel name that you're looking for which you can then use in a standard conditional.

3
  • When I do as you suggest, it outputs the entry number. Commented Mar 12, 2014 at 17:28
  • Are you sure it's the entry number and not the channel ID. I don't know why it would show the entry number for {channel}
    – foamcow
    Commented Mar 12, 2014 at 17:58
  • Yes it is definitely the entry #. Strange huh? Commented Mar 12, 2014 at 18:34

Your Answer

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

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