July 2019
Beginner to intermediate
302 pages
9h 38m
English
One of the most redundant pieces of code in HTML is that which defines input fields in forms. This is because most fields have similar code with style modifications, for example.
The following snippet is a macro that creates input fields when called. Best practice is to create the macro in a separate file for better reusability, for example, _helpers.html:
{% macro render_field(name, class='', value='', type='text') -%}
<input type="{{ type }}" name="{{ name }}" class="{{ class }}"
value="{{ value }}"/>
{%- endmacro %}
Now the macro should be imported in the file to be used, as follows:
{% from ...