{% extends "_layouts/cp" %} {% import "_includes/forms" as forms %} {% set crumbs = [ { label: "Settings"|t, url: url('settings') }, { label: "Singletons"|t, url: url('settings/singletons') } ] %} {% if singleton is not defined and singletonId is defined %} {% set singleton = blx.singletons.getSingletonById(singletonId) %} {% if not singleton %}{% exit 404 %}{% endif %} {% endif %} {% set isNewSingleton = (singleton is not defined or not singleton.id) %} {% if isNewSingleton %} {% set title = "Create a new singleton"|t %} {% else %} {% set title = singleton.name %} {% endif %} {% set tabs = { settings: { label: "Settings"|t, url: '#singleton-settings' }, fieldlayout: { label: "Field Layout"|t, url: '#singleton-fieldlayout' } } %} {% set content %}
{% if not isNewSingleton %}{% endif %}
{{ forms.textField({ first: true, label: "Name"|t, instructions: "What this singleton will be called in the CP."|t, id: 'name', name: 'name', value: (singleton is defined ? singleton.name : null), errors: (singleton is defined ? singleton.getErrors('name') : null), autofocus: true, required: true, translatable: true }) }} {% if blx.hasPackage('Language') %} {% set localesInput %} {% for locale in blx.i18n.getSiteLocales() %}
{{ forms.checkbox({ label: locale.name~' ('~locale.id~')', name: 'locales[]', value: locale.id, checked: (singleton is not defined or (singleton is defined and singleton.locales[locale.id] is defined)), toggle: 'uriRow-'~locale.id }) }}
{% endfor %} {% endset %} {{ forms.field({ label: "Locales"|t, instructions: "Which locales should this singleton be enabled in?"|t }, localesInput) }} {% endif %} {% macro uriInput(locale, singleton) %} {% import "_includes/forms" as forms %} {% set errors = singleton ? singleton.getErrors('uri-'~locale.id) : null %}
{{ forms.text({ id: 'uri-'~locale.id, class: 'code', name: 'uri['~locale.id~']', value: (singleton is defined and singleton.locales[locale.id] is defined ? singleton.locales[locale.id].uri : null), errors: errors }) }}
{{ forms.errorList(errors) }} {% endmacro %} {% from _self import uriInput %} {% set uriField %} {% if blx.hasPackage('Language') %} {% for locale in blx.i18n.getSiteLocales() %} {% endfor %}
{% else %} {{ uriInput(blx.i18n.getPrimarySiteLocale(), (singleton is defined ? singleton : null)) }} {% endif %} {% endset %} {{ forms.field({ label: "URI"|t, instructions: "The URI that should load this singleton."|t, required: true, errors: (singleton is defined ? singleton.getErrors('uri') : null) }, uriField) }} {{ forms.textField({ label: "Template"|t, instructions: "The template to use when the singleton’s URI is requested."|t, id: 'template', name: 'template', value: (singleton is defined ? singleton.template : null), errors: (singleton is defined ? singleton.getErrors('template') : null) }) }}

{% endset %}