/
Coding Advice: Push Tags in Display Pattern
Coding Advice: Push Tags in Display Pattern
Goal: Show various tags, for example, products or keywords, in a display pattern. Use the push tags code example for simpler, maintainable, 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 %}
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 %}
, multiple selections available,
Related content
Display Pattern: Using Icons, HTML and CSS
Display Pattern: Using Icons, HTML and CSS
Read with this
Display Pattern: Product Information in Download File Name
Display Pattern: Product Information in Download File Name
More like this
Dynamic View: Filter for Tagbox
Dynamic View: Filter for Tagbox
More like this
Display Pattern: Tagbox
Display Pattern: Tagbox
More like this
Display Pattern
Display Pattern
More like this
Channel Filter: Show Items with Two Specific Tags
Channel Filter: Show Items with Two Specific Tags
More like this
FotoWare Switzerland AG - CH-5033 Buchs - Switzerland
https://picturepark.com - support@picturepark.com
© 2023 FotoWare Switzerland AG