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 %}



FotoWare Switzerland AG - CH-5033 Buchs - Switzerland
https://picturepark.com - support@picturepark.com
Ā© 2023 FotoWare Switzerland AG