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?
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).
You can also use:
{#key}
Some content
{:else}
Some other content, if key doesn't have a value
{/key}
For example:
Data
{
firstName: "Mickey",
lastName: "Mouse",
website: null,
phone: "1-800-DISNEYWORLD"
}
Dust Template
<p>First Name: {firstName}</p>
<p>Last Name: {lastName}</p>
{#website}
<p>Website: {website}</p>
{:else}
<p>Phone: {phone}</p>
{/website}
Output:
First Name: Mickey
Last Name: Mouse
Phone: 1-800-DISNEYWORLD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With