0

Hoping someone can help me with this problem. I have a list of channel entries that I am storing in a stash tag then outputting the complete list, but if there are no entries then it displays something else.

What I am hoping to do is if the total count of entries == 0 then display one thing, if the count == 1 then display something else and finally if the count is > 1 then display a third option to the viewer.

Here is the code that I currently have.

{exp:stash:set name="dynamic_adventure" trim="yes" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="adventure_settings" dynamic="no" author_id="CURRENT_USER"}    

          {exp:switchee variable="{embed:adventure_name}" parse="inward"}

              {case value="{dynamic_adventure_template:title}"}

                    <a href="{path="admin/{dynamic_adventure_template:url_title}"}/{url_title}" class="button small red">View Adventure</a><br>

              {/case}
              {case value=""}

              {/case}
          {/exp:switchee}

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

{if {exp:stash:not_empty name="dynamic_adventure"} }
        <h2 class="th-adventure-title">{embed:adventure_name}</h2>
        {exp:stash:get name="dynamic_adventure"}
{if:else}
    <h2 class="th-adventure-title">{embed:adventure_name}</h2>
    <a href="{path="admin/new-adventure"}" class="button small red">Start New Adventure</a>
{/if}

Any help is greatly appreciated. Thanks

1

You can store the total_results of channel:entries on a stash variable.

{exp:stash:set name="dynamic_adventure" trim="yes" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="adventure_settings" dynamic="no" author_id="CURRENT_USER"}    

          {exp:switchee variable="{embed:adventure_name}" parse="inward"}

              {case value="{dynamic_adventure_template:title}"}

                    <a href="{path="admin/{dynamic_adventure_template:url_title}"}/{url_title}" class="button small red">View Adventure</a><br>
                    {if count == 1}
                        {exp:stash:set name="dynamic_adventure_total"}{total_results}{/exp:stash:set}
                    {/if}
              {/case}
              {case value=""}

              {/case}
          {/exp:switchee}

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

Then, you can use the variable for conditionals.

{if "{exp:stash:get name='dynamic_adventure_total'}" == "1"}
    [...]
{if:elseif {exp:stash:not_empty name="dynamic_adventure"} }
        <h2 class="th-adventure-title">{embed:adventure_name}</h2>
        {exp:stash:get name="dynamic_adventure"}
{if:else}
    <h2 class="th-adventure-title">{embed:adventure_name}</h2>
    <a href="{path="admin/new-adventure"}" class="button small red">Start New Adventure</a>
{/if}
| improve this answer | |
  • thanks for the reply. Is there something else I need to include when I set the stash? I keep getting a list_count of 1 even though it is more. – user1407 Jul 17 '13 at 21:40
  • Please, forgive me. I thought you was using a stash list, but you're using a simple stash variable. I gonna update my answer. – Robson Sobral Jul 17 '13 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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