Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It's probably caused by having PHP on Output, rather than Input, but you can avoid using PHP altogether. The way Low Events is set up, and the way Low Seg2Cat works, will allow you to set both parameters regardless of their format:

{exp:low_events:entries date="{segment_2}" category="{segment_2_category_id}"}
    ...
{/exp:low_events:entries}

If segment 2 is a date, it won't match a category, so the {segment_2_category_id} will be empty.

If segment 2 is a category, it will not match a date, so the date parameter will ignore that value and use today as the working date.

share|improve this answer
    
thanks for the solution! I tend to default to programmatically solving problems rather than trying to rely solely on the template markup. –  adamell Feb 14 '14 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.