{# @var craft \craft\web\twig\variables\CraftVariable #} {# /** * color-swatches plugin for Craft CMS 3.x * * ColourSwatches Field Input * * @author Percipio Global Ltd. * @copyright Copyright (c) 2020 Percipio Global Ltd. * @link https://percipio.london * @package Colour Swatches * @since 1.0.0 */ #} {% import "_includes/forms" as forms %} {% set defaultValue = null %} {% set options = field.useConfigFile ? palettes[field.palette] is defined ? palettes[field.palette] : field.palette == '' ? configOptions : [] : field.options %} {#{% set options = field.useConfigFile#} {# ? palettes[field.palette] is defined#} {# ? palettes[field.palette]#} {# : configOptions#} {# : field.options %}#} {% if options|length == 0 %}

{{ "The selected colour palette for this field isn\'t defined in the `colour-swatches.php` config file"|t('colour-swatches') }}

{% endif %}
{# fetch our color options #} {% for option in options %} {% include 'colour-swatches/colourOption' with { optionId: namespacedId ~ '-option-' ~ loop.index, option: option, } %} {# Set the default value #} {% if option.default %} {% set value = { label: option.label, color: option.color is defined ? option.color : option.colour, } %} {% set defaultValue = value|json_encode %} {% endif %} {% endfor %} {% if fieldValue.color is defined %} {% set fieldValue = fieldValue|json_encode %} {% else %} {% set fieldValue = '' %} {% endif %} {% set fieldValue = fieldValue ? fieldValue : defaultValue %}
{{ forms.hidden({ id: id ~ namespacedId, name: name, value: fieldValue, class: 'color-swatches-input'}) }}