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.

Problem in Conditionally exposing a field if it does not match

January 20, 2011 3:44pm

Subscribe [3]
  • #1 / Jan 20, 2011 3:44pm

    porpoise

    30 posts

    I am listing an event.  If the expiration_date day is the same as the event_date day, I want to suppress the expiration_date day.  I tried this following code but it doesn’t work.  Can you help?

    {exp:channel:entries channel="event" show_future_entries="yes" show_expired="no" orderby="date" sort="asc"}
                    <li>
                        <h5>{categories show_group="1"}{category_name}{/categories}</h5>
    <p>                    <div class="event_info"><br />
                            </p><h3><a href="http://{url_title_path=events/event}">{title}</a></h3>
    <p>                        </p><h4>{entry_date format="%F %j, %Y"} | {entry_date format="%g:%i%a"} {if show_expiration}{if expiration_date} - {if expiration_date format="%F %j %Y"<> entry_date format="%F %j %Y"}{expiration_date format="%F %j, %Y"} | {/if}{/if} {expiration_date format="%g:%i%a"}{/if}{if event_cost}
    {event_cost}{/if}</h4>
    <p>                    </div><br />
                        {event_image}<br />
                    </li><br />
                    {/exp:channel:entries}

    Of the above code - this is the piece that is causing the page to break:

    {if expiration_date format="%F %j %Y"<> entry_date format="%F %j %Y"}{expiration_date format="%F %j, %Y"} | {/if}

    What I’m trying to say is that if the expiration_date does not match the entry_date, then the expiration_date should appear.

  • #2 / Jan 21, 2011 2:52am

    John Henry Donovan

    12339 posts

    Ty something like the following.

    {if expiration_date != entry_date}{expiration_date format="%F %j, %Y"} | {/if}
  • #3 / Jan 21, 2011 3:28pm

    porpoise

    30 posts

    I don’t think it’s a problem with the comparison operator.  The issue is that I want it to compare the DAY of the entry_date with the DAY of the expiration_date.  How do I specify that within the conditional.  I tried:

    {if entry_date format="%F %j" != expiration_date format="%F %j"}{expiration_date format="%F %j, %Y"} | {/if}

    But it breaks.

    I also tried substituting single quotes with the double quotes but to no avail.

  • #4 / Jan 22, 2011 3:57pm

    Greg Salt

    3988 posts

    Hi porpoise,

    You can’t use the formatting strings of the entry/expiration dates in conditionals - that is why it is breaking. One way to do this would be to create two Snippets, one for each of the date strings you need to create. Something like this; a snippet called ‘entry_day’:

    {entry_date format="%j"}

    and a snippet called ‘expiration_day’:

    {expiration_date format="%j"}

    Now, you can use these snippets in a conditional because you do not need to add a format string:

    {if {entry_day} != {expiration_day}} ... {/if}

    Cheers

    Greg

  • #5 / Jan 24, 2011 3:50pm

    porpoise

    30 posts

    Great! Worked perfectly. Thank you so much.

  • #6 / Jan 24, 2011 4:03pm

    Ingmar

    29245 posts

    Very glad to hear it. Please post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases