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.

conditional issue

July 25, 2011 5:40pm

Subscribe [3]
  • #1 / Jul 25, 2011 5:40pm

    Jules van Schaijik

    210 posts

    I want to know whether a comment is written by the person who wrote the entry to which it belongs, or by someone else.  So, I use the MX Jumper plugin and the channel:entry to store the entries author in a new variable, {author_post}.  Later, in the comment:entries tag, I want to compare that variable (author_post) with the author variable that refers to the author of the comment.
    That’s where the trouble begins. The variables have the expected content, but the conditional is not working as expected.  For instance, this code, coming after the channel:entries tag

    {exp:comment:entries sort="asc"} 
    {author} - {author_post} are {if author_post != author }not {/if} the same!
    {/exp:comment:entries}

    leads to this output:

    Max Boor - Max Boor are not the same!

    Am I messing up the syntax for the conditional?

  • #2 / Jul 25, 2011 5:43pm

    Try:

    {if "{author_post}" != "{author}" }not {/if}
  • #3 / Jul 25, 2011 5:50pm

    Jules van Schaijik

    210 posts

    Thank you!  That works.  But what is the principle at work here?  I mean, when should I, and when should I not, use quotes and/or curly brackets?

  • #4 / Jul 25, 2011 6:55pm

    I’m not sure what the specifics are; I just use quotes and curlies on everything and never have any problems 😊

  • #5 / Jul 26, 2011 12:17pm

    Kyle Cotter

    730 posts

    Hi Jules,

    One way you can do this without having to use a plugin is utilizing the {entry_author_id} tag.

    You can setup your conditional to look like

    {if entry_author_id == author_id}
        ...
    {/if}

    This will check to see if the author id of the entry matches the id of the commenter.

    As far as when to use “” and {}, the Conditional Global Variables Page puts it nicely. Typically you would have a setup like

    {if variable comparison-operator value}
        ...
    {/if}

    Where the variable would not have “”, but the value would. For example,

    {if username == "rob"}
        ...
    {/if}

    Rob being the value, and username being the variable you are checking.

    Now, when comparing 2 variables together, such as entry_author_id, and author_id, quotes are not needed.

    When using MX Jumper, you created a custom variable, and in order to use that custom variable you needed to use curly braces. So, MX Jumper would convert the {author_post} to a value, and then you’d be comparing 2 values in the conditional.

    Hopefully this clears up any confusion you have.

    Thanks for the help here Nick.

  • #6 / Jul 26, 2011 12:30pm

    Kyle Cotter

    730 posts

    Also, there is this great F.A.Q resource on how to Troubleshoot Conditionals.

    Thanks.

  • #7 / Jul 26, 2011 8:00pm

    Jules van Schaijik

    210 posts

    Thanks very much Kyle!  I didn’t know about the entry_author_id variable.  That sure makes things a lot easier.

  • #8 / Jul 27, 2011 12:20pm

    Dan Decker

    7338 posts

    Jules,

    Looks like you are all set! I’m going to resolve this out.

    Please come back to the forums if you need further assistance.

    Best,

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

ExpressionEngine News!

#eecms, #events, #releases