{# Set attribute if value was provided. @param {string} attrName - attribute name. @param {string} attrValue - attribute value. #} {%- macro setAttr(attrName, attrValue) -%} {% set str %}{{- attrName -}}='{{- attrValue -}}'{% endset %} {%- if attrName and attrValue -%} {% if ['checked', 'selected', 'disabled', 'required', 'hidden', 'x-validation:field' ].includes(attrName) %} {{- attrName -}} {%- else -%} {{- str | safe -}} {%- endif -%} {%- endif -%} {%- endmacro -%} {# Set attributes to tag. @param {object} attributes - attributes object @example link #} {% macro setAttributes(attributes = {}) -%} {%- set str = '' -%} {%- for attr, value in attributes -%} {%- if value and attr -%} {%- set str = str + ' ' + setAttr(attr, value).val -%} {%- endif -%} {%- endfor -%} {{- str | safe -}} {%- endmacro -%} {# Insert inline svg element. @param {string} path - path to svg icon in image folder. #} {% macro svg(path = '') %} {% include (PATH.images | lower) + '/' + path + '.svg' ignore missing %} {% endmacro %} {# Get image from placehold.co service. @param {string} size - image dimensions. #} {% macro getPlaceholderImageURL(size = '200x300', format = 'jpg') %} {{ '//placehold.co/' + size + '/' + format }} {% endmacro %} {# Insert transparent image sizer. @param {number} width - placeholder width @param {number} height - placeholder height #} {% macro getEmptyImageSizer(width = 100, height = 100) %} {{- 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22'+width+'%22%20height=%22'+height+'%22%20viewBox=%220%200%20'+width+'%20'+height+'%22%20/%3E' -}} {% endmacro %} {# Helper for conditional containers @param {string} className - template class @param {string} href - can be passed and transform template to a link @param {string} tag - template tag #} {% macro templateWrapper(className = '', href = '', tag = 'div', attrs = {}) %} {% set templateTag = 'a' if href else tag %} {% if className %} <{{ templateTag }} {{ setAttr('href', href) }} class="{{ className }}" {{ setAttributes(attrs) }}> {{ caller() if caller }} {% else %} {{ caller() if caller }} {% endif %} {% endmacro %}