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 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 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.descby(opts)}}/>
{% endmacro input %}

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

{% macro xsl(opts, cls) %}{% import _self as fx %}<div class="{{cls}}">{% if opts.label != '' %}    <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 descby(opts) %}{% if opts.help != '' %} aria-describedby="{{opts.id}}Help"{% endif %}{% endmacro descby %}

{% 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 %}

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

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

{% 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 %}

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

{% macro checkbox(opts) %}
{% import _self as fx %}{%if opts.group %}{{fx.bsl({label: opts.label})}}{% endif %}
    <div class="form-check form-check-inline">
    {% for ix,val in opts.values %}
        <label class="form-check-label {{rspace is defined ? rspace : 'mr-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="mr-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>
    {% endfor %}
    {{fx.bse(opts)}}{%if opts.group %}{{fx.bse({})}}{% endif %}
{% endmacro %}

{% macro radio(opts) %}
{% import _self as fx %}{%if opts.group %}{{fx.bsl({label: opts.label})}}{% endif %}
    <div class="form-check form-check-inline">
    {% for ix,val in opts.values %}
        <label class="form-check-label {{rspace is defined ? rspace : 'mr-4'}}">
        {% if opts.ons[ix] is defined %}{{fx.on({id: opts.ids[ix], on: opts.ons[ix]})}}{% endif %}
	    <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])}}{{fx.hv('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>
    {% endfor %}
    {{fx.bse(opts)}}{%if opts.group %}{{fx.bse({})}}{% endif %}
{% endmacro %}

{% 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)}}{{fx.descby(opts)}}>{{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 datetime(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}{{fx.input('datetime', opts)}}{{fx.bse(opts)}}{% endmacro datetime %}

{% macro select(opts) %}{% import _self as fx %}{{fx.bsl(opts)}}
    <select {{fx.cv(opts.class)}}{{fx.hv('id', opts.id)}}{{fx.on(opts)}}{{fx.help(opts)}}{{fx.hv('name', opts.name)}}{{fx.fv(opts)}}{{fx.cdb(opts.multiple, 'multiple')}}{{fx.hv('size', opts.size)}}{{fx.descby(opts)}}>
        {% 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'}}" type="submit" value="{{opts.value}}"{{fx.hv('id', opts.id)}}{{fx.on(opts)}}/>{% endmacro submit %}

{% macro recaptcha(key, label, callback, opts) %}
{% import _self as fx %}
    {% if key != '' %}
        <button class="btn {{opts.style != '' ? opts.style : 'btn-primary'}} g-recaptcha" data-sitekey="{{key}}" data-callback="{{callback}}"{{fx.hv('id', opts.id)}}>{{label}}</button>
    {% else %}
        <button class="btn {{opts.style != '' ? opts.style : 'btn-primary'}}" 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}}" {% if type == 'select' %}data-value="{{value}}" {% endif %}data-name="{{name}}" data-type="{{type}}" data-pk="{{id}}" data-title="{{msg}}" data-emptytext="{{empty}}">{{value}}</a>{% endmacro inline %}
{# use this if editable breaks....
    {% macro inline(type, name, msg, id, value) %}{{value}}{% endmacro inline %}
#}

{% 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 %}