ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Excluding entries of a channel tag within another channel tag

September 14, 2012 4:32am

Subscribe [3]
  • #1 / Sep 14, 2012 4:32am

    Bhashkar Yadav

    727 posts

    Hi All,

    I am developing a site. There is slider on the home page populating recent 4 entries. On this page there is another section which is listing the channel entries of same channel as slider entries.

    In the listing, i would like to exclude the entries which are populating into slider.

    I know, it can easily done by offset parameter within channel tag.
    But the channel is associated with 5 categories and slider is populating the entries without considering the category.
    The listing is populating entries of a particular category.

    Can we have any way to overcome this issue.


    Thanks

  • #2 / Sep 14, 2012 5:20am

    Ben Parizek

    128 posts

    You can do this using the Stash addon (https://github.com/croxton/Stash).

    The basic idea will be that you create a Stash variable in your first EE tag, and then use that variable to exclude those entries by ID in the second entries tag.

    Here is a rough idea with untested code:

    Your slider code:

    {exp:channel:entries 
     channel="whatevs"
     limit="4"
     }
     
     <!-- Create a list of entry IDs that you are using.  i.e. 1|2|3|4 -->
     {exp:stash:append name="entries_ids_to_exclude"}{if count != 1}|{/if}{entry_id}{/exp:stash:append}
    
     <!-- Your slider code -->
    
    {/exp:channel:entries}

    Your other listing:

    {exp:channel:entries 
     channel="whatevs"
     entry_id="not {exp:stash:get name='entries_ids_to_exclude'}"
     }
     
     <!-- All the other entries you want to output excluding the ones above -->
    
    {/exp:channel:entries}

    As I write this, I am wondering if this will work.  You may need to include the second entries tag in an {embed} tag to pass the stash variable to it.  So, the second part may need to be an embed:

    {embed="template/template_group" entries_to_exclude="{exp:stash:get name='entries_ids_to_exclude'}"}

    And then the code in your embed template would be:

    {exp:channel:entries 
     channel="whatevs"
     entry_id="not {embed:entries_to_exclude}"
     }
     
     <!-- All the other entries you want to output excluding the ones above -->
    
    {/exp:channel:entries}
  • #3 / Sep 16, 2012 1:04pm

    Bhashkar Yadav

    727 posts

    Hi Ben,

    Thanks a lot.
    It helped me to solve my problem.

    Stash is nice add-on. I wasn’t aware about it.

    Again many thanks.

  • #4 / Nov 01, 2012 7:49pm

    retinch

    8 posts

    Is there any other way to do this using stash, but not with an embed?

  • #5 / Nov 02, 2012 8:20am

    John St-Amand

    865 posts

    Stash is all about taking advantage of parse order. Embeds parse late so they’ve been one way to take advantage of Stash from the start - the natural concern is “aren’t embeds bad?” and generally yes, if you can avoid them, do so. But the beauty of Stash, when applied creatively, is that you should easily be able to do just about everything you need to do with only one embed - total. In my usage, which really just uses the “main” stash functions and doesn’t get too advanced, I’m able to have all my entries logic in one template, stashing all the “bits” and passing them to a single “wrapper” template that contains the layout for the entire inside page view.  There are some writeups being worked on lately - Adrienne Travis in particular with her first article on template partials using Stash that was published on eeinsider.com - that really provide some great insight into how this approach can work.  And Mark Croxton posted a really detailed breakdown of Stash lists on Twitter recently. I know there is some discussion about how Stash may be used without embeds altogether - so it’s coming quickly for sure.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases