We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Conditionals, in curly brackets or not?

How Do I?

Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

I’ve been using the following conditional within an Entries loop in the past and it worked (2.9.2)

{if current_time > entry_date}

Now I need to wrap each one in curly brackets for it to work (2.10.1)

{if {current_time} > {entry_date}}

But the user guide doesn’t show a need for the brackets, what should it be?

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

No need for brackets and it works fine on 2.10.1 on my end.

       
TJ Draper's avatar
TJ Draper
222 posts
10 years ago
TJ Draper's avatar TJ Draper

There definitely should not be a need for curly brackets in this case (and rarely in any case for that matter). What exactly is going wrong when you do it without curly brackets?

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

Without the brackets the first IF conditional is ignored and the next bit of code is executed.

{exp:channel:entries channel="ch_events" show_future_entries="yes" limit="1"}
{if current_time > entry_date}        
    <h2>Results</h2>        
    {if cf_results}
        <ul>                        
            {cf_results}
            <li><a href="http://{cf_results:file}{cf_results:link-url}">{cf_results:link-text}</a></li>
            {/cf_results}
        </ul>
    {if:else}
        Results will be available soon.
    {/if}
{/if}
{/exp:channel:entries}

And it always displays the Results heading regardless of the date. The following IF condition works correctly, but when I add the brackets it only displays if the current_time is later than the entry_date.

{if current_time > entry_date}        
    <h2>Results</h2>        
    {if cf_results}
        <ul>                        
            {cf_results}
            <li><a href="http://{cf_results:file}{cf_results:link-url}">{cf_results:link-text}</a></li>
            {/cf_results}
        </ul>
    {if:else}
        Results will be available soon.
    {/if}
{/if}
       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

What are you trying to accomplish in the first place? I don’t see the point of showing future entries if your conditional is to only show entries that are already published?

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

It’s on a page that displays the details of events (orienteering races). Prior to the event date there are no results yet, so I don’t want to display the Results sub-heading. After the event has taken place I want to show the Results sub-heading, and then if the results files have been uploaded show the links to them. But if they haven’t been uploaded yet to show a message saying they will be available soon.

Pre event example

Post event example

The show_future_entries is required as the same template is used for pre and post event.

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

In the code you pasted, everything is enclosed in the {if current_date > entry_date} so you’re basically ignoring all future entries.

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

There are a whole load more fields of data, I left them out to keep the code example simple. If you look at the linked examples you will see how the whole thing hangs together.

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

I’d need the code to be able to find the issue, or more info. Are you doing two exp:channel:entries or there’s an if:else conditional for {if current_date > entry_date} ?

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

I’ve stripped it down the bare minimum and it’s still an issue.

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>Test</title> 
</head>
<body>        
{exp:channel:entries channel="ch_events" show_future_entries="yes" require_entry="yes" limit="1"}
    <h1>Date conditional test</h1>
    if current_time > entry_date
    {if current_time > entry_date}        
        <h3>This should only be visible if the current_time is larger than the entry_date</h3>        
    {/if}
    current_time = {current_time format='%D %d%S %M %Y'} / entry_date = {entry_date format='%D %d%S %M %Y'}
{/exp:channel:entries}

{exp:channel:entries channel="ch_events" show_future_entries="yes" require_entry="yes" limit="1"}
    <h1>Date conditional test</h1>
    By wrapping the individual variables in curly brackets the line doesn't show.
    
    {if {current_time} > {entry_date}}        
        <h3>This should only be visible if the current_time is larger than the entry_date</h3>        
    {/if}
    current_time = {current_time format='%D %d%S %M %Y'} / entry_date = {entry_date format='%D %d%S %M %Y'}
{/exp:channel:entries}
</body>
</html>

You can see it in action here.

This is on 2.10.1, the same code on 2.9.2 works correctly, so is this a bug?

Edit: I’ve just updated another site from 2.9.2 to 2.10.1 and the same conditional is now broken and I’ve needed to add curly braces round each variable for it to work. I have had another problem with conditionals causing problems and am now thinking that there must be some bugs in 2.10.1 with conditionals.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

I’ve just pasted your stripped down code into a template on my local 2.10.1 install and cannot reproduce, each conditional example renders the same. My install is a clean install so maybe there are some add-ons at play here, plus I’d think we would have seen this issue by now if it were wide-spread with 2.10.1. Do these two sites share any of the same add-ons? If you want to submit a support ticket with your credentials, we could go in and take a look there, as well.

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

Thanks Kevin, I’ve put in a ticket.

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
10 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

Turned out it was a bug, but Kevin’s fixed it and it will be in the next release.

       
Kurt Deutscher's avatar
Kurt Deutscher
827 posts
10 years ago
Kurt Deutscher's avatar Kurt Deutscher

I think I hit this 2 weeks back and just kept trying every permutation until it started working. Thanks for getting this one resolved Paul and Kevin!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.