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.

Format within conditional

November 29, 2011 9:00am

Subscribe [3]
  • #1 / Nov 29, 2011 9:00am

    Hi.

    I am having trouble working out how to have ‘format=“Y”’ within an conditional.

    if segment_2 == "2013" AND '{option_value format="%Y"}' == "2013"}

    I have tried everything I can think of, but I thought it would be like above.

    Does anyone know whats wrong here?

    Thanks

     

  • #2 / Nov 30, 2011 3:01am

    John Henry Donovan

    12339 posts

    Hi Chris,

    Can you show us some more of your template please and explain what you are using the conditional for?

    What version and build of EE are you using?

    Are you using any add-ons?

  • #3 / Nov 30, 2011 3:05am

    Hi John.

    I am using version 2.3.1

    I have a selection of links like so:

    <a href="/~lightand/index.php/tours/2012"><li {if segment_2 == "2012"}class="selected"{/if}>2012</li></a>

    to refine the results. I am using Cart Throb, and the option_value is within a Matrix table.

    What I am wanting to do is have any products that have 2012 (or whatever year link) as the option value year.

    I am just not entirely sure the code above is actually correct?

    Thanks

  • #4 / Nov 30, 2011 3:18am

    John Henry Donovan

    12339 posts

    Chris,

    Have you tried just using the {option_value}?
    What do you see if you add that on its own?
    What type of field are you sing for the cell in the cell in the Matrix?

  • #5 / Nov 30, 2011 3:27am

    Hi John.

    Yes I have tried without the format part. The date is saved in YYYMMDD format so it doesn’t work.

    The field type is a third party option of ‘dropdate’. It allows me to save in YMD format.

    Thanks

  • #6 / Nov 30, 2011 3:31am

    John Henry Donovan

    12339 posts

    Chris,

    Can you try just {option_value format="Y"} as per the docs for dropdate.
    Does this output the correct year when used on its own?

    Also try switching around your quotes like so

    {if segment_2 == "2013" AND "{option_value format='Y'}" == "2013"}
  • #7 / Nov 30, 2011 3:35am

    The option_value format=“Y” outputs correct, 2012 or 2013 depending on the year.

    I have tried with the quotes swapped but still nothing.

    Very strange :(

  • #8 / Nov 30, 2011 3:38am

    John Henry Donovan

    12339 posts

    Chris,

    Moving this to Community Help forum as more appropriate there.

    I can’t say for sure that it might have to do with any of the third-party add-ons you are using

    Take a look at the Matrix docs on conditionals as they may have a different syntax.

    Also try using a simple conditional just for the date field

    {if "{option_value format='Y'}" == "2013"}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases