2

Current Setup

  • I have 5 entries in the "internal_ads" channel that rotate on the homepage.
  • I have set up a category of "urgent" that has 1 entry in it.
  • I'm using stash to set a list of adverts, then running through the list in my template to get them to rotate.

What I want to happen

When an entry is added to the urgent category, I want that entry to be the only ad to display.

What I've tried

I currently have the following in my initial template that sets the stash list and works correctly for getting the 5 ads.

{stash:embed:layouts:homepage}

{!-- Set data for Internal Adverts --}
     {exp:stash:set_list name="internal_ads" parse_tags="yes" parse_depth="2"}
          {exp:channel:entries channel="internal_adverts" dynamic="no" orderby="random" limit="1"}
                    {stash:url_title}{url_title}{/stash:url_title}
                    {stash:advert_title}{title}{/stash:advert_title}
                    {stash:short_description}{short_description}{/stash:short_description}
                    {stash:homepage_image}{homepage_image}{/stash:homepage_image}
         {/exp:channel:entries}
     {/exp:stash:set_list}

I have tried the following using conditionals to try checking if there's an entry in the urgent category and if there isn't then set the list as before. If there is, then only use that entry. It doesn't want to work and I can't really see why.

{stash:embed:layouts:homepage}

{!-- Set data for Internal Adverts --}
    {exp:stash:set_list name="internal_ads" parse_tags="yes" parse_depth="2"}
        {exp:channel:entries channel="internal_adverts" dynamic="no" orderby="random" limit="1" category="36"}
            {if no_results}
                {/exp:channel:entries}
                {exp:channel:entries channel="internal_adverts" dynamic="no" orderby="random" limit="1"}
                    {stash:url_title}{url_title}{/stash:url_title}
                    {stash:advert_title}{title}{/stash:advert_title}
                    {stash:short_description}{short_description}{/stash:short_description}
                    {stash:homepage_image}{homepage_image}{/stash:homepage_image}
                {/exp:channel:entries}
            {if:else}
                {stash:url_title}{url_title}{/stash:url_title}
                {stash:advert_title}{title}{/stash:advert_title}
                {stash:short_description}{short_description}{/stash:short_description}
                {stash:homepage_image}{homepage_image}{/stash:homepage_image}
            {/if}
        {/exp:channel:entries}
    {/exp:stash:set_list}

Any help is greatly appreciated.

2 Answers 2

1

There are a few different approaches to this. In my opinion I don't think this is an appropriate use of categories: rather, I would use a custom PT checkbox-group field called 'options', or alternatively use the 'sticky' functionality. Here's how you could use a PT checkbox group:

{exp:stash:set_list
    name="data"
    parse_tags="yes"
    parse_conditionals="yes"
    parse_depth="2"
}   
    {exp:channel:entries
         channel="internal_adverts"
         dynamic="no"
         orderby="random"
    }
        {if {options:selected option="urgent"}}
            {exp:stash:set_value name="urgent" value="true"}
        {/if}

        {stash:options}{options}{/stash:options}
        {stash:url_title}{url_title}{/stash:url_title}
        {stash:advert_title}{title}{/stash:advert_title}
        {stash:short_description}{short_description}{/stash:short_description}
        {stash:homepage_image}{homepage_image}{/stash:homepage_image}

    {/exp:channel:entries}
{/exp:stash:set_list}

{!-- ==============================
TEST OUTPUT 
=================================== --}

{exp:stash:parse process="end"}

    {if "{exp:stash:urgent}"}
        {exp:stash:get_list name="data" match="#Urgent#" against="options" limit="1"}
            <h3>Skirmish mode! Just show {advert_title}</h3>
        {/exp:stash:get_list}
    {if:else}
        <h3>Regular mode, loop through all ads:</h3>
        <ul>
        {exp:stash:get_list name="data"}
            <li>{advert_title}</li>
        {/exp:stash:get_list}
        </ul>
    {/if}

{/exp:stash:parse}

There are a few further examples of using these kind of 'switches' in Stash in my level-1 tutorial here: http://www.jamessmith.co.uk/articles/expressionengine-stash-tutorial-level-1#switches

0

Not that this will fix your issue but you have an extraneous {/exp:channel:entries} tag here:

enter image description here

3
  • Could be wrong but I think he put that there on purpose, I see what he's trying to do by attempting to close the channel entries tag early and start a new one instead! Nov 9, 2013 at 14:25
  • But he doesn't start a new one later to reopen it.
    – Anna_MediaGirl
    Nov 9, 2013 at 17:26
  • You're correct here, but you've highlighted the wrong close tag in the image as the one you've referenced makes sense. The one a line from the bottom in your picture is the one that shouldn't be there. However, I realised this within about a minute of posting this question, and alas, it fixes nothing. Thank you though! Nov 11, 2013 at 10:22

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.