{% elif page and page.">
我目前在我的base.html
Pelican模板中有这个部分:
{% if article and article.author %}
<meta name="author" content="{{ article.author }}" />
<meta name="copyright" content="{{ article.author }}" />
{% elif page and page.author %}
<meta name="author" content="{{ page.author }}" />
<meta name="copyright" content="{{ page.author }}" />
{% else %}
<meta name="author" content="{{ AUTHOR }}" />
<meta name="copyright" content="{{ AUTHOR }}" />
{% endif %}
有没有一种方法可以简化这个过程,例如
<meta name="author" content="{{ publication.author }}" />
<meta name="copyright" content="{{ publication.author }}" />
发布是page
还是article
?(我想一件事永远不可能同时是一页和一篇文章?)
发布于 2020-05-01 02:41:51
你可以这样做:
{% if article.author %} {% set author = article.author %}
{% elif page.author %} {% set author = page.author %}
{% else %} {% set author = AUTHOR %} {% endif %}
{% if page or article %}
<meta name="author" content="{{ author }}" />
<meta name="copyright" content="{{ author }}" />
{% endif %}
你应该能够删除最后一个" if“,因为如果你把它放在属于页面或文章的块中,这是不必要的。
https://stackoverflow.com/questions/61041567
复制相似问题