Conditionally including content in pages

87 views
Skip to first unread message

Greg Restall

unread,
Apr 21, 2011, 1:08:48 AM4/21/11
to hakyll
Dear all,

I've been enjoying fiddling with Hakyll — it's so neat to have a
static website engine written in a programming language I both
understand and enjoy. Thanks, Jasper (and others) for all the work
you've put into it. I'm planning on moving my site over to Hakyll, and
things seem to be going very well.

I am interested in finding out the best way to do the following. I've
got lots of raw pages (currently processed a different static blog
engine), which produce the pages at http://consequently.org/writing
there's a page for each paper, and for each page, there's the abstract
(in the body of the page) and a bunch of metadata: title, citation,
name of the pdf file, doi, etc. However, some items have some pieces
of metadata and not all (only recent papers have dois, for example).

I've handled this with my previous website software — which embeds
code in templates — with a heap of conditional statements (if $doi$ is
defined, then include this here…; if $filename$ is defined, then
include this here…, etc).

What is the best practice for doing this sort of thing with Hakyll?
I'd like to have master template to indicate where all of the
components on the resulting html page will go, and then the logic in
hakyll.hs sorting out what goes where.

Any advice will be most welcome. I'm sorry if this is all explicitly
described in the references somewhere — I'm still getting my head
around how it all works.

Thanks,

Greg

Jasper Van der Jeugt

unread,
Apr 21, 2011, 4:23:00 AM4/21/11
to hak...@googlegroups.com
Hello,

Hakyll currently does not support any logic in templates -- you'll
have to do this in Haskell.

There's several options. One option is to set all fields so they can
just be "plugged in" to the template.

This might mean manually creating/concatenating some HTML.

A clean approach for that is probably to have a small template in your
hakyll.hs using blaze-html [1] which renders e.g. overview for a
paper.

[1]: http://jaspervdj.be/blaze

Hope this helps,
Cheers,
Jasper

Greg Restall

unread,
Apr 21, 2011, 9:39:06 AM4/21/11
to hakyll
That makes a lot of sense — thanks for the pointer.

I can see how I can do that in a sensible and modular way now: that's
very helpful for a newbie like me.

Cheers,

Greg

On Apr 21, 6:23 pm, Jasper Van der Jeugt <jasper...@gmail.com> wrote:
> Hello,
>
> Hakyll currently does not support any logic in templates -- you'll
> have to do this in Haskell.
>
> There's several options. One option is to set all fields so they can
> just be "plugged in" to the template.
>
> This might mean manually creating/concatenating some HTML.
>
> A clean approach for that is probably to have a small template in your
> hakyll.hs using blaze-html [1] which renders e.g. overview for a
> paper.
>
> [1]:http://jaspervdj.be/blaze
>
> Hope this helps,
> Cheers,
> Jasper
>
>
>
> On Thu, Apr 21, 2011 at 7:08 AM, Greg Restall <g...@consequently.org> wrote:
> > Dear all,
>
> > I've been enjoying fiddling with Hakyll — it's so neat to have a
> > static website engine written in a programming language I both
> > understand and enjoy. Thanks, Jasper (and others) for all the work
> > you've put into it. I'm planning on moving my site over to Hakyll, and
> > things seem to be going very well.
>
> > I am interested in finding out the best way to do the following. I've
> > got lots of raw pages (currently processed a different static blog
> > engine), which produce the pages athttp://consequently.org/writing
Reply all
Reply to author
Forward
0 new messages