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}
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" != ""} ...
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011