The Framework Code

twigs/framework/util/formmacro.twig

File List

{% macro hv(attr, value)%}{% if value != '' %} {{attr}}="{{value}}"{% endif %}{% endmacro hv %}

{% macro hvd(attr, value, dflt)%} {{attr}}="{{value != '' ? value : dflt}}"{% endmacro hvd %}

{% macro dv(attr, value)%}{% if value != '' %} data-{{attr}}="{{value}}"{% endif %}{% endmacro dv %}

{% macro dvd(attr, value, dflt)%} data-{{attr}}="{{value != '' ? value : dflt}}"{% endmacro dvd %}

{% macro cd(cond, attr, value) %}{% if cond %} {{attr}}="{{value}}"{% endif %}{% endmacro cd %}

{% macro cdb(cond, attr) %}{% if cond %} {{attr}}{% endif %}{% endmacro cdb %}

{% macro cdd(cond, attr, value, dflt) %}{% import _self as fx %}{% if cond %}{{fx.hvd(attr, value, dflt)}}{% endif %}{% endmacro cdd %}

{% macro cv(value)%} class="form-control{% if value != '' %} {{value}}{% endif %}"{% endmacro cv %}

{% macro fv(opts)%}{% import _self as fx %}{% for v in ['required', 'disabled', 'readonly'] %}{{fx.cdb(opts[v], v)}}{% endfor %}{{fx.help(opts)}}{% endmacro fv %}

{% macro numopts(type, opts) %}{% if type == 'number' or type == 'range' %}{% import _self as fx %}{{fx.hv('min', opts.min)}}{{fx.hv('step', opts.step)}}{{fx.hv('max', opts.max)}}{{fx.hv('defaultValue', opts.dvalue)}}{% endif %}{% endmacro numopts %}

{% macro fileopts(type, opts) %}{% if type == 'file' %}{% import _self as fx %}{{fx.hv('accept', opts.min)}}{{fx.cdb(opts.multiple, 'multiple')}}{% endif %}{% endmacro fileopts %}

{% macro data(opts) %}{% for k,v in opts %} data-{{k}}{% if v != '' %}="{{v}}"{% endif %}{% endfor %}{% endmacro data %}

{% macro parsley(opts) %}{% for k,v in opts %} data-parsley-{{k}}{% if v != '' %}="{{v}}"{% endif %}{% endfor %}{% endmacro parsley %}

{% macro valid(opts) %}{% for k,v in opts %} data-parsley-{{k}}{% if v != '' %}="{{v}}"{% endif %}{% endfor %}{% endmacro valid %}

{% macro help(opts) %}{% if opts.help != '' %} aria-describedby="{{opts.id}}Help"{% endif %}{% endmacro help %}

{% macro on(opts) %}{% if opts.on is defined and opts.id != '' %}{% for e,v in opts.on %}{{context.saveon(opts.id, e, v)}}{% endfor %}{% endif %}{% endmacro on %}

{% macro input(type, opts) %}
{% import _self as fx %}
<input type="{{type}}"{{fx.hv('id', opts.id)}}{{fx.fv(opts)}}{{fx.hv('name', opts.name)}}{{fx.hv('value', opts.value)}}{{fx.cv(opts.class)}}{{fx.hv('placeholder', opts.ph)}}{{fx.fileopts(type, opts)}}{{fx.numopts(type, opts)}}{{fx.data(opts.data)}}
{{fx.parsley(opts.parsley)}}{{fx.valid(opts.valid)}}//>
{% endmacro input %}

{% macro bsl(opts) %}{% import _self as fx %}<div class="mb-3">
<label class="form-label"{{fx.hv('for', opts.id)}}>{{opts.label}}{{opts.rlabel|raw}}</label>
{% endmacro bsl %}

{% macro xsl(opts, cls) %}{% import _self as fx %}<div class="{{cls}}">{% if opts.label != '' %}<label class="form-label"{{fx.hv('for', opts.id)}}>{{opts.label}}</label>{% endif %}{% endmacro xsl %}

{% macro bse(opts) %}
{% if opts.help != '' %}<small id="{{opts.id}}Help" class="form-text text-muted">{{opts.help|raw}}</small>{% endif %}
</div>
{% endmacro bse%}

{% macro slct(opts, ov) %}{% if (opts.multiple and ov.value in opts.selected) or opts.selected == ov.value %} selected="selected"{% endif %}{% endmacro slct %}

{% macro text(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('text', opts)}}{{fx.bse(opts)}}{% endmacro text %}

{% macro email(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('email', opts)}}{{fx.bse(opts)}}{% endmacro email %}

{% macro password(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('password', opts)}}{{fx.bse(opts)}}{% endmacro password %}

{% macro number(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('number', opts)}}{{fx.bse(opts)}}{% endmacro %}

{% macro range(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('range', opts)}}{{fx.bse(opts)}}{% endmacro range %}

{% macro hidden(opts) %}{% import _self as fx %}{{fx.input('hidden', opts)}}{% endmacro hidden %}

{% macro checkbox(opts) %}
{% import _self as fx %}{%if opts.group %}{{fx.bsl({label: opts.label})}}{% endif %}
    {% for ix,val in opts.values %}
        <div class="form-check{%if opts.inline %} form-check-inline{% endif %}">
            <label class="form-check-label {{rspace is defined ? rspace : 'me-4'}}">
            {% if opts.ons[ix] is defined %}{{fx.on({id: opts.ids[ix], on: opts.ons[ix]})}}{% endif %}
            <input type="checkbox" value="{{val}}"{{fx.cd(opts.names[ix] is defined, 'name', opts.names[ix])}} class="me-2{{fx.cv('class', opts.class)}}"{{fx.data(opts.data)}}{{fx.on(opts)}}
                {{fx.cd(opts.ids[ix] is defined, 'id', opts.ids[ix])}}{{fx.cdb(opts.check[ix] is defined and opts.check[ix], 'checked')}}{{fx.cdb(opts.disabled[ix] is defined and opts.disabled[ix], 'disabled')}}/>
            {{opts.labels[ix]|raw}}</label>
        {{fx.bse(opts)}}
    {% endfor %}
    {%if opts.group %}{{fx.bse({})}}{% endif %}
{% endmacro checkbox %}

{% macro radio(opts) %}
{% import _self as fx %}{%if opts.group %}{{fx.bsl({label: opts.label})}}{% endif %}
    {% for ix,val in opts.values %}
        <div class="form-check{%if opts.inline %} form-check-inline{% endif %}">
            {% if opts.ons[ix] is defined %}{{fx.on({id: opts.ids[ix], on: opts.ons[ix]})}}{% endif %}
            <label class="form-check-label {{rspace is defined ? rspace : 'me-4'}}">
                <input type="radio" value="{{val}}"{{fx.cd(opts.name is defined, 'name', opts.name)}}{{fx.cd(opts.names[ix] is defined, 'name', opts.names[ix])}} class="me-2{{fx.cv('class', opts.class)}}"
                {{fx.data(opts.data)}}{{fx.cd(opts.ids[ix] is defined, 'id', opts.ids[ix])}}{{fx.cdb(opts.check[ix] is defined and opts.check[ix], 'checked')}}{{fx.cdb(opts.disabled[ix] is defined and opts.disabled[ix], 'disabled')}}/>
            {{opts.labels[ix]|raw}}</label>
        {{fx.bse(opts)}}
    {% endfor %}
    {%if opts.group %}{{fx.bse({})}}{% endif %}
{% endmacro radio %}

{% macro textarea(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}<textarea{{fx.hv('id', opts.id)}}{{fx.fv(opts)}}{{fx.hv('name', opts.name)}}{{fx.cv(opts.class)}}{{fx.hv('rows', opts.rows)}}{{fx.hv('cols', opts.cols)}}{{fx.hv('placeholder', opts.ph)}}{{fx.on(opts)}}{{fx.data(opts.data)}}>{{opts.value}}</textarea>{{fx.bse(opts)}}{% endmacro %}

{% macro file(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('file', opts)}}{{fx.bse(opts)}}{% endmacro file %}

{% macro date(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('datetime-local', opts)}}{{fx.bse(opts)}}{% endmacro date %}
{% macro datetime(opts) %}{% import _self as fx %}{{fx.datetimelocal(opts)}}{% endmacro datetime %}
{% macro datetimelocal(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('datetime-local', opts)}}{{fx.bse(opts)}}{% endmacro datetimelocal %}
{% macro time(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('time', opts)}}{{fx.bse(opts)}}{% endmacro time %}

{% macro select(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}
    <select {{fx.cv(opts.class)}}{{fx.hv('id', opts.id)}}{{fx.on(opts)}}{{fx.hv('name', opts.name)}}{{fx.fv(opts)}}{{fx.cdb(opts.multiple, 'multiple')}}{{fx.hv('size', opts.size)}}>
        {% for ov in opts.options %}
            <option value="{{ov.value is defined ? ov.value : ov.text}}"{{fx.slct(opts, ov)}}>{{(ov.text is defined ? ov.text : ov.value)|raw}}</option>
        {% endfor %}
    </select>{{fx.bse(opts)}}
{% endmacro select %}

{% macro submit(opts) %}{% import _self as fx %}<input class="btn {{opts.bstyle != '' ? opts.bstyle : 'btn-primary'}}{{opts.class != '' ? ' '~opts.class}}" type="submit" value="{{opts.value}}"{{fx.hv('id', opts.id)}}{{fx.on(opts)}}{% if opts.disabled %} disabled {% endif %}/>{% endmacro submit %}
{% macro bsubmit(opts) %}{% import _self as fx %}<button class="btn {{opts.bstyle != '' ? opts.bstyle : 'btn-primary'}}{{opts.class != '' ? ' '~opts.class}}" type="submit"{{fx.hv('id', opts.id)}}{{fx.on(opts)}}{% if opts.disabled %} disabled {% endif %}>{{opts.value}}{{opts.rvalue|raw}}</button>{% endmacro bsubmit %}
{% macro recaptcha(key, label, callback, opts) %}
{% import _self as fx %}
    {% if key != '' %}
        <button class="btn {{opts.style != '' ? opts.style : 'btn-primary'}} g-recaptcha{{opts.class != '' ? ' '~opts.class}}" data-sitekey="{{key}}" data-callback="{{callback}}"{{fx.hv('id', opts.id)}}>{{label}}</button>
    {% else %}
        <button class="btn {{opts.style != '' ? opts.style : 'btn-primary'}}{{opts.class != '' ? ' '~opts.class}}" onclick="{{callback}}('');"{{fx.hv('id', opts.id)}}>{{label}}</button>
    {% endif %}
{% endmacro recaptcha %}

{% macro tick(val, class, label = '', disabled = FALSE) %}{% import '@content/iconmacro.twig' as i %}{{i.fa('toggle-' ~ (val ? 'on' : 'off'), class)}} {{label}}{% endmacro tick %}

{% macro htick(val, class, name, disabled, label = '') %}
{% import _self as fx %}
{{fx.tick(val, "#{class} htick", label, disabled)}}<input type="hidden" value="{{val}}" name="{{name}}[]"/>
{% endmacro htick %}

{#
{% macro inline(type, name, msg, id, value, class='ppedit', empty = '----') %}<a href="#" class="{{class}}" data-value="{{value}}" data-name="{{name}}" data-type="{{type}}" data-pk="{{id}}" data-title="{{msg}}" data-emptytext="{{empty}}">{{value}}</a>{% endmacro inline %}
#}

{% macro editable(opts) -%}{% import _self as fx %}
    <a href="#" class="editable{% if opts.class != '' %} {{opts.class}}{% endif %}"{{fx.hv('id', opts.id)}}{{fx.dv('field', opts.field)}}{{fx.dv('type', opts.type)}}{{fx.dv('key', opts.key)}}{{fx.dv('title', opts.title)}}{{fx.dv('emptytext', opts.emptytext)}}>{{opts.value}}</a>
{%- endmacro editable %}

{% macro wrap(t) %}'+{{t}}+'{% endmacro wrap %}

{% macro startform(opts) %}{% import _self as fx %}{{fx.on(opts)}}
<form{{fx.hv('id', opts.id)}}{{fx.hv('class', opts.class)}}{{fx.hvd('action', opts.action, '#')}}{{fx.hvd('method', opts.method, 'GET')}}{{fx.data(opts.data)}}{% if opts.multi %} enctype="multipart/form-data"{% endif %} role="form">
{% endmacro startform %}

{% macro endform(opts) %}</form>{% endmacro endform %}

{% macro startfset(opts) %}
<fieldset{{fx.hv('class', opts.class)}}>{% if opts.legend != ''%}<legend>{{opts.legend}}</legend>{% endif %}
{% endmacro startfset %}

{% macro endfset(opts) %}</fieldset>{% endmacro endfset %}