las plantillas de liquid.js se incorporan en env.js

This commit is contained in:
f 2021-10-27 15:18:05 -03:00
parent 921d1075b0
commit 8bcb4f066f
3 changed files with 43 additions and 22 deletions

View file

@ -1,3 +1,4 @@
{%- raw -%}
<div class="alert alert-{{ type }} alert-dismissible" role="alert"> <div class="alert alert-{{ type }} alert-dismissible" role="alert">
{{ content }} {{ content }}
@ -5,3 +6,4 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
{%- endraw -%}

View file

@ -1,3 +1,4 @@
{%- raw -%}
<section class="row no-gutters justify-content-center"> <section class="row no-gutters justify-content-center">
<div class="col-10"> <div class="col-10">
{% for item in results %} {% for item in results %}
@ -15,3 +16,4 @@
{% endfor %} {% endfor %}
</div> </div>
</section> </section>
{%- endraw -%}

17
env.js
View file

@ -10,3 +10,20 @@ window.env = {
window.site = { window.site = {
"i18n": {{ site.i18n | jsonify }} "i18n": {{ site.i18n | jsonify }}
} }
{%- comment -%}
Para agregar plantillas que se procesan con JS, las agregamos en
Liquid dentro de assets/templates/ y luego las importamos acá, de forma
que estén disponibles para JS sin tener que descargarlas.
Es importante que la plantilla esté envuelta por el tag `{% raw %}`,
para que no sea procesado en el momento de generar env.js, sino en el
navegador.
{%- endcomment -%}
{%- capture alert %}{% include_relative assets/templates/alert.html %}{% endcapture -%}
{%- capture results %}{% include_relative assets/templates/results.html %}{% endcapture -%}
window.templates = {
"alert": {{ alert | markdownify }},
"results": {{ results | markdownify }},
}