Dust if condition

Tom Feeney picture Tom Feeney · Feb 22, 2013 · Viewed 23.7k times · Source

I'm having trouble with a dust if condition. I have a partial that points to 2 different dust templates depending on the Country code

{>"receipt/merchantInfo/merchantInfo_{countryCode}"/}

I'm trying to make an if else condition that will figure out if the {countryCode} is US. Example:

{@if cond="'{countryCode}' == 'US'"}
<p>is country code US</p>
{:else}
<p>is NOT country code US</p>
{/if}

This isn't working. Anyone have an idea where I went wrong with this?

Answer

smfoote picture smfoote · Feb 22, 2013

The @if helper has been deprecated because of a potential security hole (it uses eval on the condition). I would recommend using the @eq helper instead.

{@eq key=countryCode value="US"}
  <p>is country code US</p>
{:else}
  <p>is NOT country code US</p>
{/eq}

If that doesn't work, make sure countryCode is available in your context (you can use {@contextDump/} for that).