0

I have a multi site EE set up and I have set up a snippet to use in my template. The snippet syntax is {current_site_name} and the content that the snippet outputs is {site_name}

I am trying to use this snippet in the following if statement:

{if current_site_name == "Site 1"}
    <a href="tel:{site1_phone}">{site1_phone}</a>
{if:elseif current_site_name == "Site 2"}
    <a href="tel:{site2_phone}">{site2_phone}</a>
{if:elseif current_site_name == "Site 3"}
    <a href="tel:{site3_phone}">{site3_phone}</a>
{if:else}
    <h1>{current_site_name}</h1>
{/if}

The if statement doesn't seem to work, the else condition just gets run every time even though the value that it outputs matches one of the site names like Site 1, Site 2, Site 3

1 Answer 1

1

If you look at the parse order of the template engine, you'll see that although snippets do get parsed before conditionals, standard global variables (which includes {site_name}) don't get parsed until after conditionals are evaluated. This means that you are literally using "{site_name}" in your string comparison, which of course never matches any of your conditions.

The good news is that MSM variables ({site_id}, {site_label}, and {site_shortname}) are parsed right after snippets and well-before conditionals, so you can use one of those in your conditional block instead.

Your Answer

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

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