The challenge
Let’s imagine you are in a menu component in WCM, and you want to validate if some pieces of content has a very specific value in their Keywords property; in case they have it we would like to add a featured CSS class to the rendered HTML.
The solution
Following is an example about how to use the plugin Equals in IBM WCM 8 and 8.5:
<li class="item [Plugin:Equals text1='[Property field="keywords"]' text2='featured']featured[/Plugin:Equals]"> <h3>[Property context="autofill" type="content" field="title"]</h3> [Plugin:ifNotEmpty value="[Element context='autofill' type='content' key='thumbnail' rendition='auto']"] <div class="item__thumbnail"> [Element context="autofill" type="content" key="thumbnail" rendition="auto"] </div> [/Plugin:ifNotEmpty] </li>
Explanation
- The plugin Equals requires two parameters: text1 and text2. In this example, we have text1=”[Property field=”keywords”]” and value2=”featured”.
- When WCM renders this HTML with meta-tags will compare text1 and text2 in orden to see if both are equals, in case of true, the CSS class featured will be added.
I hope you find useful this information and you use in your next WCM implementation, and remember, be happy with your code!
is there a way to implement and or or condition in equals plugin
Hi, according to the IBM official documentation, it is not possible to create those kind of conditions in a single plugin call. In that case, in order to have the same result you can create two plugin calls:
OR Condition
[Plugin:Equals text1='first-condition' text2='first-condition-to-compare']
First condition
[/Plugin:Equals]
[Plugin:Equals text1='sec-condition' text2='sec-condition-to-compare']
Second condition
[/Plugin:Equals]
AND Condition
[Plugin:Equals text1='first-condition' text2='first-condition-to-compare']
[Plugin:Equals text1='sec-condition' text2='sec-condition-to-compare']
First condition AND Second condition
[/Plugin:Equals]
[/Plugin:Equals]
Best regards.