Speak to our experts today 0333 004 0333
Speak to one of our experts today
User Guides

EKM Conditional Tokens

Conditional tokens allow you to output only the markup you need when outputting data in a tag. They around an attribute tag and any accompanying markup and if the attribute tag isn't output, neither is the markup.

The example below shows a typical [ekm:showdata] output_item with a name, price, rrp and short description.

Example

[ekm:showdata]
...
output_item='
  <div class="item">
    <div class="item-name">[name]</div>
    <div class="item-price">[price]</div>
    <div class="item-rrp">[rrp]</div>
    <div class="item-shortdescription">[shortdescription]</div>
  </div><-- item -->
';
...
[/ekm:showdata]
						

When a product with a name, price, RRP and short description is output you will see markup as shown below.

Example

<div class="item">
  <div class="item-name"><a href="product-name-p-1asp">This is the product name</a></div>
  <div class="item-price">£123.99</div>
  <div class="item-rrp">£321.99</div>
  <div class="item-shortdescription">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam, libero qui vero dicta quae..</div>
</div><-- item -->
						

This is exactly how we want to display this information if the product can output it. The problem comes however when some products have RRPs and some products do not. If a product didn't have a short description or an RRP for example you would see the markup shown below.

Example

<div class="item">
  <div class="item-name"><a href="product-name-p-1asp">This is the product name</a></div>
  <div class="item-price">£123.99</div>
  <div class="item-rrp"></div>
  <div class="item-shortdescription"></div>
</div><-- item -->
						

Here you see that you're left with markup without any contents. This can cause spacing issues in your design, which you don't want.

With the addition of conditional tokens we can wrap the markup and attribute tag. If those attributes don't output (for example RRP or Short Description) none of the markup is shown.

Example

[ekm:showdata]
...
output_item='
  <div class="item">
    {name}<div class="item-name">[name]</div>{/name}
    {price}<div class="item-price">[price]</div>{/price}
    {rrp}<div class="item-rrp">[rrp]</div>{/rrp}
    {shortdescription}
      <div class="item-shortdescription">
        [shortdescription]
      </div>
    {/shortdescription}
  </div><-- item -->
';
...
[/ekm:showdata]
						

Would output the following if no RRP or Short Description is set for the product.

Example

<div class="item">
  <div class="item-name"><a href="product-name-p-1asp">This is the product name</a></div>
  <div class="item-price">£123.99</div>
</div><-- item -->