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.

{exp:channel:entries limit="1"} conditional

August 30, 2011 3:59am

Subscribe [4]
  • #1 / Aug 30, 2011 3:59am

    Ryan

    31 posts

    I am using the same entries template for my main, category and archive views.

    {exp:channel:entries channel="blog" limit="5" status="not closed"}
         <div>{title}</div>
    {/exp:channel:entries}

    However conditionally, I am needing to set offset=“1” on only one of those templates.

    Could anyone please explain how I could achieve this?

    EDIT: offset=“1”

  • #2 / Aug 30, 2011 4:09am

    Dave @ Exp:resso

    465 posts

    Why do you need to set limit=“1”? EE automatically knows if you are displaying a single entry, based on the URL.

    I would suggest using a different template for list view (for cat/archive) and detail view (for a single entry). Just makes things easier to follow. If you must put it all in one template, then do something like {if segment_2 != '' AND segment_2 !='category'}use channel entries loop with limit=1 for single entry{if:else} show channel entries loop with limit=5 or whatever for a list view{/if}. Hope that makes sense!

  • #3 / Aug 30, 2011 4:10am

    Ryan

    31 posts

    Why do you need to set limit=“1”?

    Doh! I’m so sorry, I meant to set offset=“1”.

    Apologies I’ll amend this!

  • #4 / Aug 30, 2011 4:12am

    Dave @ Exp:resso

    465 posts

    No problem, but same solution applies 😊

  • #5 / Aug 30, 2011 4:15am

    Ryan

    31 posts

    I would suggest using a different template for list view (for cat/archive) and detail view (for a single entry). Just makes things easier to follow. If you must put it all in one template, then do something like {if segment_2 != '' AND segment_2 !='category'}use channel entries loop with limit=1 for single entry{if:else} show channel entries loop with limit=5 or whatever for a list view{/if}. Hope that makes sense!

    No problem, but same solution applies 😊

    Right, so does that mean I write the same markup for each conditional?

    I figured this, but I was hoping I could somehow just modify the tag pair instead of having to include the {exp:channel:entries} markup, it will be identical for all of the conditions.

    Perhaps there is a way I can set the markup as a variable and return it in the conditions?

  • #6 / Aug 30, 2011 4:19am

    Ryan

    31 posts

    Perhaps there is a way I can set the markup as a variable and return it in the conditions?

    ... and then I remember embed/snippets ...  😝

  • #7 / Aug 30, 2011 4:21am

    Dave @ Exp:resso

    465 posts

    Yep but you dont need snippets, you can have more than one channel entries loop in a template, and just use conditionals (based on the url) to determine which one to use

  • #8 / Aug 30, 2011 4:24am

    Ryan

    31 posts

    Yep but you dont need snippets, you can have more than one channel entries loop in a template, and just use conditionals (based on the url) to determine which one to use

    I mean something like;

    {if !segment_2}
        {exp:channel:entries offset="1"}
            {embed="blog/article"}
        {exp:channel:entries}
    {else}
        {exp:channel:entries}
            {embed="blog/article"}
        {exp:channel:entries}
    {/if}

    That way I don’t have to reproduce the same markup for either condition when I use {embed="blog/article"}.

    I just hope using an embed or snippet in a loop doesn’t effect load times.

    Thanks for your help again Dave!

  • #9 / Aug 30, 2011 4:27am

    Dave @ Exp:resso

    465 posts

    Yep glad you got it sussed! We usually try to use separate templates for list/detail views now, its just tidier for us, and more efficient. I don’t know the specifics (our developers do) but EE actually parses everything on a template in some cases, before choosing what to display with the conditional, which can cause issues and slow things down.

  • #10 / Aug 30, 2011 4:32am

    Ryan

    31 posts

    I don’t know the specifics (our developers do) but EE actually parses everything on a template in some cases, before choosing what to display with the conditional, which can cause issues and slow things down.

    You’re talking me into it.

    So if I require templates for /blog/archive/2011/08 and /blog/category/general do I simply add templates archive and category to my blog template group?

  • #11 / Aug 30, 2011 4:54am

    Dave @ Exp:resso

    465 posts

    Well your archive & category templates can be exactly the same, just separate list vs detail templates is what I’m saying. So it would be /blog/archive/category/category_url_title. You wouldn’t want/need a template called ‘category’ since EE uses that keyword to automatically know to limit entries to a certain category. SO the previous url would simply use the archive template, and automatically feed in the category_url_title to whatever channel entries tag you had on the page. Make sense?

  • #12 / Aug 30, 2011 9:34am

    Sue Crocker

    26054 posts

    Thanks for the assist, Dave.

    Josephs, there are many different ways you can do content, but keep in mind that you won’t need to have a separate template for categories, if you use category as a trigger word, you be OK. Does that help?

  • #13 / Aug 30, 2011 9:37am

    Ryan

    31 posts

    SO the previous url would simply use the archive template, and automatically feed in the category_url_title to whatever channel entries tag you had on the page. Make sense?

    Josephs, there are many different ways you can do content, but keep in mind that you won’t need to have a separate template for categories, if you use category as a trigger word, you be OK. Does that help?

    Thanks for your help, I’ve got my template up and running now.

    I ended up using the single template with the conditional, the markup was duplicated for each condition.

    Probably not the way I wanted to do it, but as we’ve divulged; the only way (besides using multiple templates).

  • #14 / Aug 31, 2011 4:07am

    John Henry Donovan

    12339 posts

    Glad you have a workable solution. Thanks Dave for you help on this one. Feel free Josephs to start anew thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases