0

我有一个鹈鹕博客。我想以编程方式调用外部链接列表,而不是将它们硬编码到模板中。例如,博客文章类别以编程方式调用,例如,

{% for category, articles in categories[0:10] %}
<li><a href="/{{ category.url }}">{{ category }}</a></li>
{% endfor %}            
</div>
<div class="l-box pure-u-1-3">

{% for category, articles in categories[11:20] %}
<li><a href="/{{ category.url }}">{{ category }}</a></li>
{% endfor %}
</div>
<div class="l-box pure-u-1-3">
{% for category, articles in categories[21:30] %}
<li><a href="/{{ category.url }}">{{ category }}</a></li>
{% endfor %}

所以要明确一点,我希望将此代码更改为从列出一些外部网络链接的单个文件中调用。

4

1 回答 1

2

将它们分配给LINKS您的变量,pelicanconf.py例如

LINKS = (
   ('my link 1', 'http://some.link.here'),
   ('my link 2', 'http://some.other.link.here')
)

然后在您的模板中调用它们

{% for name, link in LINKS %}
    <a href="{{ link }}">{{ name }}</a>
{% endfor %}

在您的 中定义的所有变量pelicanconf.py,只要它们是全大写的,都可以在您的模板中访问。

请参阅:http ://docs.getpelican.com/en/3.5.0/themes.html#templates-and-variables

于 2015-03-23T09:50:53.977 回答