Reputation: 829
I have a Pelican blog. I want to call the external links list programmatically, rather than hard code them into the template. For example, the blog post categories are called programmatically, e.g.,
{% 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 %}
So to be clear, I am looking to change this code to call from a single file which lists some external weblinks.
Upvotes: 0
Views: 133
Reputation: 5554
Assign them to the LINKS
variable in your pelicanconf.py
e.g.
LINKS = (
('my link 1', 'http://some.link.here'),
('my link 2', 'http://some.other.link.here')
)
and then call them in your template with
{% for name, link in LINKS %}
<a href="{{ link }}">{{ name }}</a>
{% endfor %}
All variable defined in your pelicanconf.py
, as long as they are in all-caps, can be accessed in your templates.
See: http://docs.getpelican.com/en/3.5.0/themes.html#templates-and-variables
Upvotes: 2