3

I'm using Stash lists to output channel entries grouped by the value of a custom field. In this case the custom field is a relationship field, but that's not relevant because the actual entries output is working just fine. What is giving me problems is using the {count} variable to apply a heading to each group of entries. Here's my code (for simplicity I've removed most of the variables that I'm stashing and just including the 'reviewtext' one).

<!-- STASH variables -->
{exp:channel:entries channel="reviews" disable="categories|member_data|pagination" show_expired="yes" cache="yes" refresh="10"}
    {exp:stash:append_list name="entries" context="{reviews_assigned_project:channel_short_name}" parse_conditionals="yes"}
        {stash:reviewtext}{reviews_review}{/stash:reviewtext}
    {/exp:stash:append_list}
{/exp:channel:entries}

<!-- book reviews -->
{exp:stash:get_list name="entries" context="books" process="end"}
    {if {count} == 1}
        <h2>Book reviews</h2>
    {/if}
    <article>
        {reviewtext}
        {count} of {total_results}
    </article>
{/exp:stash:get_list}

<!-- comic reviews -->
{exp:stash:get_list name="entries" context="comics" process="end"}
    {if {count} == 1}
        <h2>Comic book reviews</h2>
    {/if}
    <article>
        {reviewtext}
        {count} of {total_results}
    </article>
{/exp:stash:get_list}

The output is fine apart from the conditional, which is output verbatim, with the exception that the value of {count} is parsed into the page. So, when I have three book reviews and two comic reviews, I get the following:

<!-- book reviews -->
{if 1 == 1}
    <h2>Book reviews</h2>
{/if}
<article>
    ... my entry content ...
    1 of 3
</article>

{if 2 == 1}
    <h2>Book reviews</h2>
{/if}
<article>
    ... my entry content ...
    2 of 3
</article>

{if 3 == 1}
    <h2>Book reviews</h2>
{/if}
<article>
    ... my entry content ...
    3 of 3
</article>

<!-- comic reviews -->
{if 1 == 1}
    <h2>Comic book reviews</h2>
{/if}
<article>
    ... my entry content ...
    1 of 2
</article>

{if 2 == 1}
    <h2>Comic book reviews</h2>
{/if}
<article>
    ... my entry content ...
    2 of 2
</article>

I've tried wrapping the conditional in exp:ifelse tags, and I've tried using Switchee instead of the {if} conditional. In every case the conditional tags (of whatever sort, including the ifelse and switchee tags) are output as template code. I tried stashing the count as a variable but that gives me the count from the entire channel entries tag rather than the count of the list output - so my book reviews have counts of 1, 3 and 4, whilst my comic reviews have counts of 2 and 5. Not what I'm after.

What am I doing wrong and how can I get the stash:list's count to work in the conditional statement? Thanks.

1 Answer 1

2

Try adding parse_conditionals="yes" to your get_list. I think the issue is parse order for the conditionals on the get_list because you are using process="end". Does this work (I also added a prefix parameter for the count):

<!-- book reviews -->
{exp:stash:get_list 
    name="entries" 
    context="books"
    parse_tags="yes" 
    parse_conditionals="yes"
    prefix="st"
    process="end"
}
    {if {st:count} == 1}
        <h2>Comic book reviews</h2>
    {/if}
    etc....
2
  • Romans-8---31-39: That did it! I hadn't realised that parse_conditionals could be used on the Get tags -- I don't think the documentation mentions it. But simply adding that parameter got the conditional to process properly, and I didn't need the prefix either. Thanks.
    – RickL
    Nov 7, 2013 at 20:11
  • Yeah, it seems like it was removed from the tag documentation for some reason, but is used in some examples. Not sure if that's an accident or things are changing - maybe if Mark Croxton runs across this he'll chime in. Nov 7, 2013 at 20:15

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.