1

I have the following code:

    {exp:switchee variable="{exp:stash:get name='custom_sidebar_text'}/{exp:stash:get_list name='related_articles'}/{exp:stash:get_list name='related_events'}" parse="inward"}

      {case value="//"}{/case} {!-- Ignore no value --}

      {case default="Yes"}

        <aside class="{exp:stash:get name='sidebar_class'} {exp:stash:get name='sidebar_shifts_up'} {exp:stash:get name='page_color' random}">

        {!-- A bunch of markup here. --}

        </aside>

      {/case}
    {/exp:switchee}

If I understand correctly, the first case should only apply if all three of the variables are empty, while the second case should apply if any one, two or all three of the variables contain something. However, in practice, if the first variable is empty, no markup is rendered, and the fact that one or both of the second and third variables have information in them is ignored completely.

I tried using value="''/''/''" in the first case, but that did not work, as it resulted in the second (default) case always being rendered, even when all three variables are empty.

Maybe exp:stash:get_list isn’t the proper way to test whether a stash list is empty? I haven’t found an alternate way of testing it, though.

2 Answers 2

2

exp:stash:get_list is a variable pair.

So, try exp:stash:list_count:

{exp:switchee variable="{exp:stash:get name='custom_sidebar_text'}/{exp:stash:list_count name='related_articles'}/{exp:stash:list_count name='related_events'}" parse="inward"}

  {case value="/0/0"}{/case} {!-- Ignore no value --}

  {case default="Yes"}

    <aside class="{exp:stash:get name='sidebar_class'} {exp:stash:get name='sidebar_shifts_up'} {exp:stash:get name='page_color' random}">

    {!-- A bunch of markup here. --}

    </aside>

  {/case}
{/exp:switchee}

I have to confess that I don't know if exp:stash:list_count returns "0" or "" and I can't test right now.

1
  • !Alfonso, what the exp:stash:list_count returns? "0" or ""? I want to update my answer.
    – Sobral
    Oct 31, 2013 at 20:57
0

@Robson Sobral

I've just tested this - if the list is not set, list_count returns "" so this pseudo code is works:

            {case value=""}
               <h4>No favourites yet!</h4>
            {/case}
            {case default="yes"}
            {/case}

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.