{# @var craft \craft\web\twig\variables\CraftVariable #} {# @var entry \craft\elements\Entry #} {# m-caption ------------------------------------------------------------ #} {# -- Set Defaults -- #} {% set defaults = { cn: 'm-caption', modifiers: [], customClasses: [], data: {}, js: null, element: 'figcaption', headline: null, text: null, source: null, sourceUrl: null } %} {# -- Merge Default with Options -- #} {% set opt = opt is defined ? defaults|merge(opt) : defaults %} {# -- Modul -- #} {% if opt.headline ?? null or opt.text ?? null %} <{{ opt.element }} class="{{ opt.cn }} {% for modifier in opt.modifiers %} {{ modifier | length ? ' ' ~ opt.cn ~ '--' ~ modifier }} {% endfor %} {% for customClass in opt.customClasses %} {{ customClass | length ? ' ' ~ customClass }} {% endfor %} {{ opt.js ? opt.cn|replace({ 'm-' : 'js-' }) : '' }}" {% for key, value in opt.data %} {{ 'data-' ~ key ~ '=' ~ value }} {% endfor %}> {# -- Headline --#} {% if opt.headline ?? null %} {{- opt.headline ~ ' ' -}} {% endif %} {# -- Caption -- #} {{ opt.text ?? null }}{{ opt.source ? ' — ' }} {# -- Caption Source Url -- #} {% if (opt.source ?? null) and (opt.sourceUrl ?? null) %} {# -- link -- #} {% include '_atoms/link/_template.html' with { opt: { modifiers: ['inline'], url: opt.sourceUrl ?? null, targetBlank: true, text: opt.source ?? null, icon: null, } } only %} {% elseif opt.source ?? null %} {{ opt.source }} {% endif %} {% endif %}