templating

10 views
Skip to first unread message

brian

unread,
Oct 27, 2010, 4:06:48 PM10/27/10
to hakyll
I don't understand how to populate fields in templates when the source
of the data is not a "page". How can I cause $foo to be populated
from, e.g., a String?

Jasper Van der Jeugt

unread,
Oct 27, 2010, 6:53:46 PM10/27/10
to hak...@googlegroups.com
Hello,

There are different ways to do this. Could you elaborate a bit, so I
can explain the best way for your specific problem?

Cheers,
Jasper

Gwern Branwen

unread,
Oct 27, 2010, 7:05:59 PM10/27/10
to hak...@googlegroups.com
On Wed, Oct 27, 2010 at 6:53 PM, Jasper Van der Jeugt
<jasp...@gmail.com> wrote:
> Hello,
>
> There are different ways to do this. Could you elaborate a bit, so I
> can explain the best way for your specific problem?
>
> Cheers,
> Jasper

To hijack this thread a little, someone pointed out to me today that
bookmarking pages on my site was much harder than it needed to be
because the <title> was the same on every page.

I had removed the $title bit which I had copied from
http://jaspervdj.be/hakyll/index.html because it apparently only took
the data from a metadata block inside each Markdown page, and I didn't
want to clutter my 100 .pages with a metadata block containing the
filename; and had forgotten about this change.

So template.html went from

<title>Hakyll - $title</title>

to

<title>Joining Clouds</title>

However, just dropping the .page suffix would suffice to get the
title. But I'm not sure how the plumbing works or even whether this
could work.

--
gwern
http://www.gwern.net

brian

unread,
Oct 27, 2010, 7:19:55 PM10/27/10
to hakyll
On Oct 27, 6:53 pm, Jasper Van der Jeugt <jasper...@gmail.com> wrote:
> There are different ways to do this. Could you elaborate a bit, so I
> can explain the best way for your specific problem?

I get my posts with getRecursiveContents. I want to create a sidebar
with a list containing entries like "2010-09 (3)" that link to pages
containing the posts made that month. I wrote code to gather the
information I need from the post paths, but I don't know how to render
it.

My default.html already uses $body. I'd like to be able to also code
$archiveList there and populate it from a String, since the data
$archiveList needs does not come from a "page".

Jasper Van der Jeugt

unread,
Oct 28, 2010, 8:16:11 AM10/28/10
to hak...@googlegroups.com
I've released 2.4 which should make this easier. The two methods
you'll want to have a look at are:

- addField (in CreateContext) which can be used to add a field to a context
- takeBody, (in ContextManipulations) which can be used to render to a string

Cheers,
Jasper

brian

unread,
Oct 28, 2010, 11:12:41 AM10/28/10
to hakyll
On Oct 28, 8:16 am, Jasper Van der Jeugt <jasper...@gmail.com> wrote:
> I've released 2.4 which should make this easier. The two methods
> you'll want to have a look at are:
>
> - addField (in CreateContext) which can be used to add a field to a context
> - takeBody, (in ContextManipulations) which can be used to render to a string

Thanks for doing this, Jasper. But I guess I don't understand how to
use addField.

I tested like
let postPages = map ((>>> addField "foo" (Left "blah")) . createPage)
postPaths

$foo isn't being replaced with "blah". In that same template, $body
*is* replaced.

Greg

unread,
Oct 28, 2010, 1:04:52 PM10/28/10
to hakyll
Hi Brian, it is possible that you might be experiencing the same
frustration that I blogged about- (I was trying to add a sidebar of
recent posts- see end of the post, contains a link to my hakyll file.
http://blog.gregweber.info/posts/2010-10-12-hakyll-hamlet

Gwern Branwen

unread,
Oct 29, 2010, 12:57:14 PM10/29/10
to hak...@googlegroups.com
On Thu, Oct 28, 2010 at 8:16 AM, Jasper Van der Jeugt
<jasp...@gmail.com> wrote:
> I've released 2.4 which should make this easier. The two methods
> you'll want to have a look at are:
>
> - addField (in CreateContext) which can be used to add a field to a context
> - takeBody, (in ContextManipulations) which can be used to render to a string
>
> Cheers,
> Jasper

Was this meant as a reply to my question about $title as well?

--
gwern
http://www.gwern.net

Jasper Van der Jeugt

unread,
Oct 30, 2010, 6:14:37 AM10/30/10
to hak...@googlegroups.com
You seem to be using addField in a correct way, it should work. Could
I have a look at the bigger picture to figure out what's wrong?

Cheers,
Jasper

Reply all
Reply to author
Forward
0 new messages