以编程方式为 Pelican 站点调用链接列表
Call links list programatically for Pelican site
我有一个 Pelican 博客。我想以编程方式调用外部链接列表,而不是将它们硬编码到模板中。例如,以编程方式调用博客 post 类别,例如
{% 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 %}
明确地说,我希望更改此代码以从列出一些外部网络链接的单个文件中调用。
将它们分配给 pelicanconf.py
中的 LINKS
变量,例如
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
我有一个 Pelican 博客。我想以编程方式调用外部链接列表,而不是将它们硬编码到模板中。例如,以编程方式调用博客 post 类别,例如
{% 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 %}
明确地说,我希望更改此代码以从列出一些外部网络链接的单个文件中调用。
将它们分配给 pelicanconf.py
中的 LINKS
变量,例如
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