Data Composition in Tobey
I've just finished implementing basic data composition in Tobey. This is a feature that allows you to create data from content for use within templates, with a simple YAML DSL. Here's an example:
composer:
posts:
template: post.html
sort_by: id
This will create a posts
variable that contains all entries in the "blog" directory, sorted by their YAML meta-data id
, in descending order. This data can then be used in templates to render the blog posts, for example:
{{ for post in posts }}
<article>
<h2>{{ post.title }}</h2>
<p>{{ post.date }}</p>
<p>{{ post.content }}</p>
</article>
{{ end }}
And in fact, I use this exact data composition for the front page of this very website of mine. It currently only supports where
and sort
clauses, and the where
clauses only support ==
comparisons, but I plan to expand on this in the future, and I want to add a where_not
, where_in
, where_not_in
, offset
and limit
clauses as well, which should allow for pretty complex use cases.