Website PortalGuideDesignersContent Editors

Display a Data Collection field IF NOT empty

With this little bit of code, you can dynamically display fields based on whether or not the...

With this little bit of code, you can dynamically display fields based on whether or not the values are empty.

For example, let's say you have a field called Color. And when there is no value for the Data Item you don't want the <p> line with 'My Color:" to display with no value. So you can check if the value of Coloris empty. If the fields value is empty DO NOT render the HTML between the IF statement. If it's value is not empty, then proceed to display the line in the layout.

{% if color != "null" -%}<br /> <p>My Color: {{color}}</p> <br />{% endif -%}
Data Collection

Originally sourced from the BlueberryCMS knowledge base.

Was this article helpful?