1

I have a stash set list that's getting all the entries from a channel as follows;

{exp:stash:set_list name="items-{segment_2}" parse_tags="yes" parse_depth="3"}
    {exp:tag:related_entries
        channel="items"
        orderby="title"
        sort="asc"
    }
        {stash:item_id}{entry_id}{/stash:item_id}
        {stash:item_title}{title}{/stash:item_title}
        {stash:item_count}{count}{/stash:item_count}
    {/exp:tag:related_entries}
{/exp:stash:set_list}

I'm then using a get list as follows, first to get the first 3 items and then again to get all the rest in the "more_items" div;

<h1>Items <a href="">View more</a></h1>

<div class="items">
{exp:stash:get_list name="items-{segment_2}" limit="3"}
{item_title}
{/exp:stash:get_list}
</div>

<div class="more_items">
{exp:stash:get_list name="items-{segment_2}" offset="3"}
{item_title}
{/exp:stash:get_list}
</div>

You'll notice I have a h1 that contains a link to View more. This has some JS to handle the reveal of the "more_items" div. However, i'd like to hide the View more link if there are only 3 or less items.

I have tried moving the heading inside the first list but because it is limited by 3 it can't figure out if there are more than 3 to show the link.

I would be grateful if anyone has any advice. :)

4
2

You can use a standard EE conditional with (https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Alist_count%7D) the stash function list_count to do this. list_count can be used to return the total count, or the count of a filtered list. Very handy!

1

Could you not use the {count} or {absolute_results} function ?

{exp:stash:get_list name="items-{segment_2}" parse_conditionals="yes"}
//^ parse_conditionals may be required
{if absolute_results >= 3}<h1>Items <a href="">View more</a></h1>{/if}
//^ unsure of wrapping results, may need {} ??
{/exp:stash:get_list}

<div class="items">
{exp:stash:get_list name="items-{segment_2}" limit="3"}
{item_title}
{/exp:stash:get_list}
</div>

<div class="more_items">
{exp:stash:get_list name="items-{segment_2}" offset="3"}
{item_title}
{/exp:stash:get_list}
</div>

Obviously if you "view more" conditional sat directly beneath the {get_list limit="3"} you could put the conditional inside and save an additional query.

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.