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.

Hide Entries

January 20, 2011 11:22pm

Subscribe [5]
  • #1 / Jan 20, 2011 11:22pm

    cjorgensen

    393 posts

    Why does:

    {exp:channel:entries channel="letters" 
    {if segment_1 !=""}require_entry="yes"{/if} dynamic="yes" 
    status="no_reply|Open|{if logged_in}Draft{/if}" disable="pagination|categories|member_data" limit="1"}

    Not work? I can’t get it to show the draft entries regardless of whether I’m logged in or not.

    Basically, I want to be able to preview draft entries and even make a comment before putting the entry live, so I’ll take other suggestions on better ways to do this. Secondarily I would like to know why my solution failed. This is my third run at this with the same results, so giving up until I get some feedback from someone the knows what I am doing wrong.

  • #2 / Jan 21, 2011 12:20am

    Cheif

    626 posts

    I’m not sure of the technicalities but pretty sure you cant put {if} statements inside exp:channel tags

    Try instead using embed and pass variables to it.. ie:

    page template:

    {if logged_in}
    {embed="group/allgoodtemplate"}
    {/if}
    {if logged_out}
    {embed="group/nogoodtemplate"}
    {/if}

    Make both templates with exp:channel:entries tags hard coded to allow/disallow certain items.

    You can even pass variables to the embed template, but thats another story !!

  • #3 / Jan 21, 2011 10:45am

    Ingmar

    29245 posts

    Why does ...not work?

    Parse order. You can’t use conditionals and EE tags inside parameters. In your case you’d need to break it up, like so:

    {if logged_in}
     {exp:channel:entries channel="letters" status="no_reply|Open|Draft"}
      ...
     {/exp:channel:entries}
    {/if}
    
    {if logged_out}
     {exp:channel:entries channel="letters" status="no_reply|Open"}
      ...
     {/exp:channel:entries}
    {/if}
  • #4 / Jan 21, 2011 11:03am

    cjorgensen

    393 posts

    I’m close to understanding.

    Is the

    {if segment_1 !=""}require_entry="yes"{/if}

    part illegal the way I am using it then? It seems to be working.

    [Update: More or less I am wondering if the below is also valid.]

    {exp:channel:entries channel="letters" {if segment_1 !=""}require_entry="yes"{/if} dynamic="yes"  {if logged_in}status="no_reply|Open|Draft"{/if} 
    {if logged_out}status="no_reply|Open"{/if} disable="pagination|categories|member_data" limit="1"}
  • #5 / Jan 21, 2011 1:28pm

    cjorgensen

    393 posts

    Well, to answer my own question that didn’t work either, so I’m going to do it Ingmar’s way. Still trying to wrap my head around why it fails, but the URL segment check is fine there (unless it’s not).

  • #6 / Jan 21, 2011 5:03pm

    Ingmar

    29245 posts

    URL segments are parsed much earlier than other global variables to allow exactly for something like

    {exp:channel:entries url_title="{segment_3}" ...}

    or similar.

  • #7 / Jan 22, 2011 12:14am

    cjorgensen

    393 posts

    I’m moving further away from understanding, not closer.

    I tried enclosing the entire channel output in the logged in/out tags and it outputs nothing regardless of my state or the status of the posts.

    I’m obviously doing something wrong, but no idea what. I’ve got ifs piled on top of ifs in that template (elements that only show if a custom field is full or empty mostly) and they all work. I am kind of treating the ifs as “divs” in my head (if one opens it has to close, the close of one doesn’t have to be the the next closing tag) and not html elements (tags are closed by the next closing tag of the same kind).

    So I enclosed that entry in a logged in tag, added “draft” the entries that are supposed to show, and it’s not even pulling “Open” entries.

    I did the same for the logged out tag, and have it as I currently have my template. And it pulls nothing.

    Will take another run at it sometime tomorrow, but I don’t even have a theory as to what I could be doing wrong at this point.

    I added the logged in and out tags to the sidebar titles and the link will show up (it’s the perma link). Is this because those are embeded?

    Thanks for the help so far. I never got this to work on my EE1.6x site either, and I eventually just gave up. If it’s easier to restrict to a member group that is acceptable to me as well (and has obvious advantages). I only picked logged in status because I am the only site member.

  • #8 / Jan 22, 2011 11:39am

    cjorgensen

    393 posts

    I created a new template to dink with, since I was getting frustrated. I pulled everything off it that wasn’t needed.

    I was having a problem with a combination of URL segment parsing, require entries, and a 404 redirect in the event of no results.

    I added everything back in slowly and it seems to be working.

    Am I wrong in that the tags inside the if_logged in tags still get parsed?

    I had:

    {if no_results}
    {redirect="404"}
    {/if}

    If I pull those out it seems to work correctly. I’m making the assumption that I either have them in the wrong place or that since the logged in state is preventing results that these fire off even through they are within the channel entries. I’ll look into that later today. So much closer.

  • #9 / Jan 23, 2011 5:55pm

    Greg Salt

    3988 posts

    Hi Christopher,

    With regards to your first questions, conditional statements inside tag declarations may sometimes work depending on their context but that is incidental and they should never be used. The correct way to deal with this would be either Ingmar’s or Cheif’s methods. For the last part of your question about if logged_in, I’m not sure what you are driving at really. Can you please post the template code that you are having trouble with?

    Cheers

    Greg

  • #10 / Jan 24, 2011 12:28pm

    cjorgensen

    393 posts

    What I have:

    {exp:channel:entries channel="letters" {if segment_1 !=""}require_entry="yes"{/if} dynamic="yes" status="no_reply|Open" disable="pagination|categories|member_data" limit="1"}
      {if no_results}
    {redirect="404"}
    {/if}
      <div class="content">
      <h1>Dear {title}</h1>
      <div class="content_letter">
      
    {content_letter}
      </div><!--This closes the letter -->
    
    {if content_reply !=""}
      <h2>Reply:</h2>
    <p>    <div class="content_reply"><br />
        <br />
        {content_reply}</p>
    
    <p>        <br />
    {if website !=""}<br />
            <br />
            <div class="reply_website"><br />
        Website: <a href="http://{website}" title="{website}">{website}</a> <br />
            </div><!--This closes the website --><br />
        <br />
    {/if}<br />
              </div><!--This closes the reply --></p>
    
    <p>  <br />
      <br />
       <div class="content_graphic"><br />
       <br />
       {content_graphic}<br />
       <br />
        <br />
        </div><!--This closes the graphic --><br />
        <br />
    {/if}  <br />
     {/exp:channel:entries}

    What I want is the status of “Draft” to be seen by logged in people, but not others. If I blanket the above in:

    {if logged_}{exp:channel:entries channel="letters" {if segment_1 !=""}require_entry="yes"{/if} dynamic="yes" status="no_reply|Open|Draft" disable="pagination|categories|member_data" limit="1"}
      {if no_results}
    {redirect="404"}
    {/if}
    
    ...
    
    {/exp:channel:entries}{/if}

    And then have the same for logged out without the Draft status it dies. It sounds like I’m not doing things in the preferred manner regardless.

    When I pull out the

    {if no_results}
    {redirect="404"}
    {/if}

    portion of the template it works fine. I’m probably going to pull out the “require entry” portion of the tag (since it’s not supposed to be there). I’m not exactly sure what will be lost by doing this regardless. There should always be an entry, so if there isn’t that page is incorrect.

  • #11 / Jan 25, 2011 8:23am

    Sue Crocker

    26054 posts

    Christopher..

    Try something like this:

    {if logged_in}
    {exp:channel:entries channel="letters" status="open|draft"}
    {if:else}
    {exp:channel:entries channel="letters" status="open"}
    {/if}
    ........
    {/exp:channel:entries}

    So you are using one opening exp:channel:entries tag or the other depending on whether or not you’re logged in.

    Does that help?

  • #12 / Jan 25, 2011 11:13am

    cjorgensen

    393 posts

    Ah, that’s exactly what I want. It seemed a bit silly to have to repeat that much code to effectively add one word. It works by repeating that much code, but isn’t very elegant.

    I took the if statement out of the original tag, since it’s not supposed to be there. If I decided that I need to force entries I’ll tackle that then.

  • #13 / Jan 25, 2011 11:55am

    cjorgensen

    393 posts

    {if logged_in}
      {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open|Draft" disable="pagination|categories|member_data" limit="1"}
      {if:else}
        {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open" disable="pagination|categories|member_data" limit="1"}
    {/if}

    Gives me the Draft result regardless of my logged in state. I see it either way.

    If I try to apply this same syntax to the post titles link list I get an unexpected if syntax error and it doesn’t parse.

    I also tried to limit it by member group instead and it still displays.

    {if member_group == '1|6'}
      {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open|Draft" disable="pagination|categories|member_data" limit="1"}
      {if:else}
        {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open" disable="pagination|categories|member_data" limit="1"}
    {/if}

    No idea what I am doing wrong.

  • #14 / Jan 26, 2011 3:27am

    John Henry Donovan

    12339 posts

    Christopher,

    You need the complete channel:entries tag for both conditions. You can’t break it between conditionals like that

    {if logged_in}
      {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open|Draft" disable="pagination|categories|member_data" limit="1"}
    ...Everything in-between…
     {/exp:channel:entries}
      {if:else}
        {exp:channel:entries channel="letters" dynamic="yes" status="no_reply|Open" disable="pagination|categories|member_data" limit="1"}
    ...Everything in-between…
     {/exp:channel:entries}
    {/if}

    Let us know if that works for you

  • #15 / Jan 26, 2011 9:34pm

    cjorgensen

    393 posts

    I got this and the other 4 I wanted to work working, so yay!

    The one thing I don’t get from this is why the conditional has to enclose the entire channel entry. Is this a parse order thing?

    I’ve spent so much time on the conditional docs over the last two days that I’d think I’d have them nailed by now, but I am getting there.

    I got the help I needed. Thanks.

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

ExpressionEngine News!

#eecms, #events, #releases