I am quite new to Expression Engine and am trying to get a handle on the template system. I have a nav with items that I want to set to active if they link to the current page

I have the link built like this so far:

<a href="{site_url}ranges/view/{url_title}">

The comparison I want to do is as follows:

if ((site_url + 'ranges/view' + url_title) == current_url) -> output class="active"

I have tried the following but I get a Parse/Syntax Error:

<a href="{site_url}ranges/view/{url_title}" {if (site_url + 'ranges/view/' + url_title) == current_url}class="active"{/if}>

What am I doing wrong?

2 Answers 2


Do you really want to compare the whole url? If not, it is easier to only compare the entry url_title and the url_title from the current url like this:

{if url_title == segment_3}class="active"{/if}

Here you can find more information about url segments.

  • You my friend, are a life saver :) Thanks for the link about segments, interesting feature
    – Mikey
    Commented Jan 15, 2016 at 9:22

I expect that you're getting parse errors as EE can't handle the "+" symbol, as it's for mathematical addition, not concatenation.

But fundamentally it won't work as {site_url} is parsed late, so can't be used in conditionals, see here for parse order details or more depth here on the EE website.

I've written out the solution in another Stack Exchange post, which is to use a custom config variable, the alternative is replace site_url and hard code the protocol & domain, but that's not good if you have multiple environments.

Be aware of the downfalls of comparing url_title with segment_3 in a conditional, as this will match true even if there is a segment_4 in the url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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