在Pelican中,页面的内容以形式传递到Jinja2模板page.content
。假设其中page.content
包含一个string {REPLACEME}
。我现在如何{REPLACEME}
用某些模板逻辑的结果替换此字符串,例如
{% for pub in publications %}
{% set key, year, text, bibtex, doi, url, pdf, slides, poster = pub %}
{% if "%s"|format(year) == "%s"|format(yr) %}
<li id="{{ key }}">{{ text }}</li>
{% endif %}
{% endfor %}
我的想法是,我想使用模板逻辑来呈现项目列表,但仍然能够决定该列表应在哪里出现page.content
。
我知道,有一个replace()
过滤器在Jinja2的,但我无法弄清楚如何使new
论点包含模板ouptut从上面。
原来Jinja2中有宏。
{% macro bibtex_rendered() -%}
{% for pub in publications %}
{% set key, year, text, bibtex, doi, url, pdf, slides, poster = pub %}
{% if "%s"|format(year) == "%s"|format(yr) %}
<li id="{{ key }}">{{ text }}</li>
{% endif %}
{% endfor %}
{%- endmacro %}
然后,我可以在调用中使用已定义的宏replace
:
{{ page.content | replace("{PUBLICATIONS}", bibtex_rendered()) }}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句