So basically we need to check the pattern of a segment and if it doesn't match our patterns we go on to start our entries loop with a category (via seg2cat).
if {segment_2}
is a date, it's either formatted YYYY-MM
or YYYY-MM-DD
, otherwise it's a string.
<?php
$this->EE =& get_instance();
$seg2 = $this->EE->uri->segment(2);
$date_pattern_half = '/^[0-9]{4}-(0[1-9]|1[0-2])$/';
$date_pattern_full = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/';
if( preg_match($date_pattern_full, $seg2) || preg_match($date_pattern_half, $seg2) ) {
?>
{exp:low_events:entries channel="calendar" date="{segment_2}"}
<?php } else { ?>
{exp:low_events:entries channel="calendar" category="{segment_2_category_id}"}
<?php } ?>
... do stuff with entries here ...
{/exp:low_events:entries}
The error we're getting back is:
Parse error: syntax error, unexpected '}' in /server/domain/system/expressionengine/libraries/Functions.php(679) : eval()'d code on line 68
for reference, the above function in Functions.php is:
/**
* eval()
*
* Evaluates a string as PHP
*
* @access public
* @param string
* @return mixed
*/
function evaluate($str)
{
return eval('?'.'>'.$str.'<?php ');
}
As for the 'line 68' val it's just a closing </ul>
tag.
I should also note that when we remove the opening loops ({exp:low_events:entries}
) we don't get this error.
We've tried the alternative syntax <?php else: ?>
etc but we get an unexpected T_ELSE
instead of the one above.