The challenge
Imagine you want to know if there is a non-empty value in any element of a Authoring Template, because if there is no value, then a set of HTML tags should not be generated; well, maybe you could solve this problem by using a small JavaScript code, but, let’s face it, most of our user don’t have a really great connection and since the JavaScript is executed completely in the client, the user experience could not be the best possible.
The solution
Ok, we have a server-side solution using the ifNotEmpty plugin, which is really easy to use, let’s see an example:
[Plugin:ifNotEmpty value="[Element context='current' type='content' key='linkURL' format='url']"] <div class="ad-link"> <a href="[Element context="current" type="content" key="linkURL" format="url"]"> [Element context="current" type="content" key="linkURL"] </a> </div> [/Plugin:ifNotEmpty]
Explanation
The plugin ifNotEqual requires one mandatory parameter: value (which is basically an string). In this example, we have value=”[Element context=”current” type=”content” key=”linkURL”]”.
When WCM renders this HTML with the [Element] meta-tag, it will compare the value and if it is not empty, the HTML inside the plugin will be rendered, otherwise no HTML will be generated. So, as simple as that, we validate the element value and depending on it, we generate some HTML.
I hope you find this information useful, and remember, be happy with your code!