Skip to content

Instantly share code, notes, and snippets.

@dario61081
Created August 5, 2022 19:38
Show Gist options
  • Save dario61081/01e05ed30a78d80183b6a6a7443203f8 to your computer and use it in GitHub Desktop.
Save dario61081/01e05ed30a78d80183b6a6a7443203f8 to your computer and use it in GitHub Desktop.
macros for jinja templates
{% macro render_field(field) %}
{% if field.type != 'HiddenField' %}
<div class="field {% if field.errors %} error {% endif %}">
{{ field.label }}
<div class="ui input">
{{ field }}
</div>
{% if field.errors %}
<span>{{ field.errors[0] }}</span>
{% endif %}
</div>
{% else %}
{{ field }}
{% endif %}
{% endmacro %}
{% macro submit(text,style='primary') %}
<button class="ui button {{ style }}" type="submit">{{ text }}</button>
{% endmacro %}
{% macro submit_danger(text) %}
<button class="ui button red" type="submit">{{ text }}</button>
{% endmacro %}
{% macro volver(url) %}
<a href="{{ url }}" class="ui button tertiary"> <i class="left chevron icon"></i> Volver </a>
{% endmacro %}
{% macro check_valid() %}
<div class="field">
<label class="danger">Activar acci&oacute;n</label>
<input class="ui checkbox" type="checkbox" name="valid" id="valid"
onclick="$('#valid').setAttribute('disabled', $(this).target.value)">
Estoy seguro de ejecutar esta acci&oacute;n.
</div>
{% endmacro %}
{% macro breadcrum(path) %}
<div class="ui breadcrumb">
<a class="section">Home</a>
<div class="divider"> /</div>
<a class="section">Store</a>
<div class="divider"> /</div>
<div class="active section">T-Shirt</div>
</div>
{% endmacro %}
{% macro render_form(form) %}
{% for f in form %}
{{ render_field(f) }}
{% endfor %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment