Post Image
By Matt GaidicaApril 17, 2012In Uncategorized

Conditional Tag Pair Content in Expression Engine

While working with the Exp:resso Store in an Expression Engine install, I ran into a small issue because I needed to expose conditional content based on me knowing if a tag pair has anything in it. Exp:resso allows all the store’s products to have what they call “modifiers”, which is the way that you control selecting a small shirt versus a large shirt on a shirts product page.

<div class="box-these-in">
  <option ... >
  <option ... > 
  <option ... > 
</div>

My problem is that I want to contain all the modifiers within a DIV block, meaning I need one DIV for [x] amount of modifiers. The catch is that I don’t want any container to show up unless there are modifiers present. The options for the modifiers tag pair are sparse, as they are already within a “{exp:store:products}” tag pair, so I could not use a count or limit option that I normally would for this. Here was my hack to make this work.

{if "{modifiers}{modifier_name}{/modifiers}" != ""}
  <div class="box-these-in">
{/if}
{modifiers}
  <option ... >
{/modifiers}
{if "{modifiers}{modifier_name}{/modifiers}" != ""}
  </div>
{/if}

Shirts

As you can see, this just exploits the fact that the modifiers tag pair has a “modifier_name” field present if a modifier exists. With the shirt example, you are essentially making the following comparison if there were modifiers for shirt size, shirt color, and shirt style.

{if "SizeColorStyle" != ""} ...
svgSimple Twitter User Authentication with Node.js, Express, Mongoose, and Passport
svg
svgCreating a Simple Expression Engine Plugin