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.

conditionals in limit or status for exp:channel:entries seem to go wrong

October 11, 2011 7:55pm

Subscribe [3]
  • #1 / Oct 11, 2011 7:55pm

    tim_diggins

    12 posts

    Hi -

    I’m embedding a template twice in different places with different embed variables (e.g. ‘limit’) each time.

    The template then outputs the embed variables (for debugging purposes, and then uses them like this:

    {exp:channel:entries limit="embed:limit"} ....{/exp:channel:entries}

    Weirdly, the output value is as I expect (10 in one place 2 in another).
    However the number of items retrieved in both exp:channel:entries tagpair, is 2.

    This feels like a bug, or am I using embeds in an unexpected way?

     

  • #2 / Oct 11, 2011 8:04pm

    tim_diggins

    12 posts

    Sorry - posted too fast.

    I misdiagnosed the problem. It’s nothing to do with posting twice. (That was just my error).
    The problem is actually when I try the following:

    limit="{if embed:limit}{embed:limit}{if:else}2{/if}"
    {exp:channel:entries limit="{if embed:limit}{embed:limit}{if:else}2{/if}" }
    {/exp:channel:entries}

    This outputs limit=“10” (or whatever my embed limit was)
    but the exp:channel:entries acts as if an empty limit was put in.

    This also occurs if I replace the limit with simple conditionals:

    limit="{if embed:limit}{embed:limit}{/if}{if embed:limit==''}2{/if}"

     

  • #3 / Oct 11, 2011 8:26pm

    tim_diggins

    12 posts

    Ok, I’m getting more clarity on this:

    The problem seems to be whenever I have a conditional in a status= or limit= parameter (maybe more) of a {exp:channel:entries} tag, e.g.

    {exp:channel:entries channel="mychannel" status="open{if logged_in}|otherstatus{/if}" require_entry="yes"}

    This is a bigger problem than the previous one with limit and embed templates (I can work around that one.

  • #4 / Oct 12, 2011 1:19am

    John Henry Donovan

    12339 posts

    Hi tim,


    You should be approaching it this way

    {if logged_in}
    {exp:channel:entries channel="mychannel" status="open|otherstatus" require_entry="yes"}  
    ...
    {/exp:channel:entries}
    {/if}
    
    {if logged_out}
    {exp:channel:entries channel="mychannel" status="open" require_entry="yes"}  
    ...
    {/exp:channel:entries}
    {/if}


    regarding the limit you could try this syntax but untested

    limit="{if '{embed:limit}' != ''}{embed:limit}{/if}{if '{embed:limit}'==''}2{/if}"

     

  • #5 / Oct 12, 2011 3:02am

    tim_diggins

    12 posts

    Hi John

    thanks for your reply, but why “should”? The ... in each case is identical, so why would I want to repeat that bit of code twice? I’d really want a strong justification for going the way you suggested.

    Is there a problem with having status using an embed variable or conditional?

    As for the limit, why do you think that adding the quotes round the {embed:limit} would help?
    It isn’t a problem (as far as I can tell) with the conditional itself (it outputs fine, right?) but rather with the conditional (any conditional) being in the limit/status parameter.

  • #6 / Oct 12, 2011 11:28am

    Mark Bowen

    12637 posts

    Hi Tim,

    This is most likely down to a matter of parse order here.

    Trying to use variables or embedded variables inside tag parameters like this is not supported and most of the time will not work due to parse order.

    You can find out exactly what is going on here by going to Admin > System Administration > Output and Debugging and turning on the Display Template Debugging? option.

    If you see your embed variables looking like {embed:my_variable} in the output there then this is showing that they are not being parsed early enough to be available to the tag.

    This is why you will need to do things as John mentioned.

    Does that help at all?

    Thanks,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases