[Solved]-Jekyll templates using django-like liquid blocks / inheritance


I’m not sure this is ever going to work within Jekyll. I might be wrong, but here’s my reasoning:

Each page is rendered out using do_layout in https://github.com/mojombo/jekyll/blob/master/lib/jekyll/convertible.rb

This works recursively – it processes the content of the page, then processes the page’s layout, then that layout’s layout and so on and so forth, passing the YAML variables up the chain (so they’re always available in parent templates as {{ page.whatever}}).

This means that the only things which get passed up are the YAML values, and whatever the value of ‘content’ is after it has been processed by Liquid. I don’t know how it is done elsewhere, but that seems incompatible with the idea of blocks, as they’d require you to pass up the two blocks separately.

Fundamentally, it seems to me that the issue is that Jekyll already has a simple form of inheritance – via the “layout” attribute that you can give to a layout. Fundamentally, I think that this is compatible with liquid-templating.

All that said, I’m not sure that you’ve exhausted the limits of using YAML, _includes, and template logic. If you’re at the point of putting Django style blocks into your content, why not just do something like this:


title: some title
secondary_content: |
    Here is some *secondary* content that will be [markdownified](http://example.com).
    It can run to multiple lines and include
    * Lists
    * Good things
    * Etc

And here is the main content, as per usual


    <h1>{{ page.title }}</h1>
    {{ content }}
{{ page.secondary_content | markdownify}}

If you wanted to keep your templates clean, and have different content for different types of pages, you could use various includes:


{% include sidebar_negotiation.html %}


{% if page.type = 'foo' %}
{% include sidebar_foo.html %}
{% else if page.type = 'bar' %}
{% include sidebar_bar.html %}
{% endif %}

And then put your page type specific stuff in those files. Obviously you could include it directly, but it is probably nice to abstract it out. Those includes will get all of the variables in the YAML.

If none of this is a win, you could always try Hyde: http://hyde.github.com/ which is written in Python, uses Jinja2 (basically Django templates++), and does the same sort of thing.

Leave a comment