apostrophe cms - A way to override standard html output by apos.schemas.field() -
does know how override/extend behavior of apos.schemas.field()
have output custom html?
i've tried implement contact form doing 'their way', quite disappointed @ level of control apostrophe cms gives on markup outputs.
i style inputs bootstrap , add additional attributes inputs, apos.schemas.field method not seem accept other parameter readonly flag, wondering if extend method accept object instead, contain necessary data need, i.e. class, data attributes etc.
there several ways can it.
if want change output fields of particular schema field type, can override appropriate template in lib/modules/apostrophe-schemas/views
, such string.html
.
the standard version of template imports macros.html
, invokes schemas.string
, et cetera, don't have that.
what have is:
make sure field's entire content wrapped in outer element
data-name
attribute, set schema field name. including label or other content should shown , hidden input field.make sure field has
name
attribute set schema field name. applies field types, see macros.html unusual cases tag , join editors.
in general: markup yours change data-
attributes , name
attribute must stay same.
"what if want conventional formatting in apostrophe's forms, , special formatting in forms?" 1 way set style
property on field in schema, so:
{ name: 'flavor', type: 'string', style: 'custom' }
then string.html
can this:
{%- import "macros.html" schemas -%} {% if (data.style == 'custom') %} {# custom way #} <div data-name="{{ data.name }}"> <h4>{{ data.label }}</h4> <input name="{{ data.name }}" /> </div> {% else %} {# normal way #} {{ schemas.string(data) }} {% endif %}
notice makes custom
style available form on site choose use when adding fields. note can use addfields
restate definition of standard field if want change, let's say, title
use custom style.
"where output current value of field?" don't. schema module javascript set on fly, , read well, 1 reason why must follow data-name
, name
attribute conventions.
Comments
Post a Comment