1

I'm using a Solspace Tag - Related Entries to show tagged entries. On the page, I show the first 3 channel entries and then wish to show a link to view more entries, but only if there are more than 3 entries to show.

I'm struggling to get a conditional working to show/hide the link based on the count of items in the results, while using Stash.

Here's my template;

{exp:stash:set name="itinerary_events"}
    {exp:tag:related_entries
        channel="event"
        orderby="event_date"
        sort="asc"
        limit="3"
        paginate="bottom"
    }
    {title}
    {/exp:tag:related_entries}
{/exp:stash:set}

{exp:stash:set name="itinerary_events_more"}
    {exp:tag:related_entries
        channel="event"
        orderby="event_date"
        sort="asc"
        limit="15"
        paginate="bottom"
        offset="3"
    }
    {stash:count}{count}{/stash:count}
    {title}
    {/exp:tag:related_entries}
{/exp:stash:set}

{exp:stash:set_list name="itinerary-vars" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries
        channel="{channel}"
        status="open"
        limit="1"
    }
        {stash:tag}{exp:tag:tags entry_id="{entry_id}" limit="1" websafe_separator="-"}{tag}{/exp:tag:tags}{/stash:tag}
    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:set name="content"}

    {exp:stash:get_list name="itinerary-vars"}

<div class="box">
    {if "{exp:stash:get name='count'}" > "3"}<a href="#">View all</a>{/if}

    {exp:stash:get name="itinerary_things"}

    {exp:stash:get name="itinerary_things_more"}
</div>

    {/exp:stash:get_list}

{/exp:stash:set}

I would be grateful if anyone might be able to help. Thank you.

2

Since your question is about the View All link setup, I removed the itinerary-vars set_list. There's no need to run your exp:tag:related_entries tag twice when you're using Stash. Let Stash do the work to cut down on db queries.

{exp:stash:set_list name="itinerary_events" parse_tags="yes"}
    {exp:tag:related_entries
        channel="event"
        orderby="event_date"
        sort="asc"
        limit="4"
    }
        {stash:event_title}{title}{/stash:event_title}
        {stash:event_count}{count}{/stash:event_count}
    {/exp:tag:related_entries}
{/exp:stash:set_list}

{exp:stash:set name="content"}
    <div class="box">
        {exp:stash:get_list name="itinerary_events"}
            {if "{event_count}" == 4}<a href="#">View all</a>{/if}
            {if "{event_count}" <= 3}<h1>{event_title}</h1>{/if}
        {/exp:stash:get_list}
    </div>
{/exp:stash:set}
| improve this answer | |

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.