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?
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}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.
The show_future_entries is required as the same template is used for pre and post event.
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.