Discussion:
[hakyll] Rendering a template twice with variable substitution
e***@gmail.com
2015-06-23 21:26:21 UTC
Permalink
Say I have the usual template post-list.html that renders a list of
posts—this template accesses the field $posts$. Now, I want to render that
template twice using two different lists. In my exact situation, one is the
list of all blog posts (with the field $posts$), and the second is the list
of blog posts with a certain tag (with the field $postsTaggedWithX$).

How would I be able to do this without copy-pasting the template?
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kyle Marek-Spartz
2015-06-24 15:03:52 UTC
Permalink
You should be able to. I do something similar on my site using
partials. Both tag specific pages and the blog list reference the
post-list partial:

https://github.com/zeckalpha/kyle.marek-spartz.org/blob/master/templates/tag.html

https://github.com/zeckalpha/kyle.marek-spartz.org/blob/master/templates/blog.html
Post by e***@gmail.com
Say I have the usual template post-list.html that renders a list of
posts—this template accesses the field $posts$. Now, I want to render that
template twice using two different lists. In my exact situation, one is the
list of all blog posts (with the field $posts$), and the second is the list
of blog posts with a certain tag (with the field $postsTaggedWithX$).
How would I be able to do this without copy-pasting the template?
--
Kyle Marek-Spartz
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
e***@gmail.com
2015-06-24 16:49:05 UTC
Permalink
You reference the post-list partial in two different pages, right? I want
to reference the post-list partial twice on the *same* page, but using two
different lists.

A non-DRY solution I'm using is to do something like this (in index.html):

$for(posts)$
$partial("templates/post-list-item.html")$
$endfor$

$for(postsTaggedWithX)$
$partial("templates/post-list-item.html")$
$endfor$

A solution I'm looking for would look something like:

$partial("templates/post-list.html", posts)$
$partial("templates/post-list.html", postsTaggedWithX)$
Post by Kyle Marek-Spartz
You should be able to. I do something similar on my site using
partials. Both tag specific pages and the blog list reference the
https://github.com/zeckalpha/kyle.marek-spartz.org/blob/master/templates/tag.html
https://github.com/zeckalpha/kyle.marek-spartz.org/blob/master/templates/blog.html
Post by e***@gmail.com
Say I have the usual template post-list.html that renders a list of
posts—this template accesses the field $posts$. Now, I want to render
that
Post by e***@gmail.com
template twice using two different lists. In my exact situation, one is
the
Post by e***@gmail.com
list of all blog posts (with the field $posts$), and the second is the
list
Post by e***@gmail.com
of blog posts with a certain tag (with the field $postsTaggedWithX$).
How would I be able to do this without copy-pasting the template?
--
Kyle Marek-Spartz
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...