Goal: Show various tags e.g. products, or keywords in a display pattern. Use the push tags code example to have simpler, maintainable and faster code.

Prettify with Push Explained

When you have a Display Pattern with lots of values, you can prettify your code using the following logic.

1. Create an array (name: tags) for looping through terms
	{% array tags %}

2. Push values (into the array)
	{% push tags%}
    	{% if data.basicInformation %}
      		{{data.basicInformation | layer_name: "BasicInformation"}}
	{% elsif data.productInformation %}
	    {{data.productInformation | layer_name: "ProductInformation"}}
	{% endif %}
	{%endpush%}
	{% push tags%}
	{% for mediaType in data.imageAndUsageInformation.mediaType %} {{mediaType | tagbox_name}}{% endfor %}
	{%endpush%}

3. Check if something is in the array
	{% if tags.size > 0 %}

4. Display the values from the array with a filter: | uniq - which means unique values only
	{{tags | uniq | join: " | " }}

5. Show values in case array is empty
	{% else %}
    	{% if data.imageMetadata.fileName %}
        	{{data.imageMetadata.fileName}}
	    {% else %}
    	    {{id}}
    	{% endif %}
	{% endif %}
JSON

Complete Push Code Example

{% array tags %}

{% push tags%}
    {% if data.basicInformation %}
        {{data.basicInformation | layer_name: "BasicInformation"}}
{% elsif data.productInformation %}
    {{data.productInformation | layer_name: "ProductInformation"}}
{% endif %}
{%endpush%}

{% push tags%}
{% for mediaType in data.imageAndUsageInformation.mediaType %} {{mediaType | tagbox_name}}{% endfor %}
{%endpush%}

{% if tags.size > 0 %}
    {{tags | uniq | join: "_" | downcase}}
{% else %}
    {% if data.imageMetadata.fileName %}
        {{data.imageMetadata.fileName}}
    {% else %}
        {{id}}
    {% endif %}
{% endif %}
CODE