including specified files in a layout?

69 views
Skip to first unread message

Rich Morin

unread,
Feb 23, 2012, 4:03:18 PM2/23/12
to liquid-t...@googlegroups.com
I'm using Jekyll to create single-page web applications,
using GitHub Pages for deployment.

My _layouts/recipe.html file uses Liquid's include tag
to incorporate HTML and CoffeeScript content into the
document's HEAD, eg:

{% include demo_1/external_js.html %}

<script type="text/coffeescript">
# <![CDATA[
{% include demo_1/lib_chart.coffee %}
{% include demo_1/lib_query.coffee %}
{% include demo_1/lib_table.coffee %}
{% include demo_1/main.coffee %}
# ]]>
</script>

This works OK for a demo, but it isn't a general solution.
In order to use the layout with multiple pages, I need a
way to let the page specify which files to include.

Suggestions?

-r
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume r...@cfcl.com
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Software system design, development, and documentation

Rich Morin

unread,
Feb 23, 2012, 4:27:37 PM2/23/12
to liquid-t...@googlegroups.com
It's possible to define fields in the page's YAML header
and use them in the layout. Unfortunately, the "include"
tags make this unworkable, AFAICT.


One thought I had was to use a capture in the page body,
then evaluate it in the layout, eg:

Layout:

{{ cs_code }}

Page:

{% capture cs_code %}


<script type="text/coffeescript">
# <![CDATA[
{% include demo_1/lib_chart.coffee %}
{% include demo_1/lib_query.coffee %}
{% include demo_1/lib_table.coffee %}
{% include demo_1/main.coffee %}
# ]]>
</script>

{% endcapture %}


Problem is, I'm not sure how to name the capture variable
so that it passes between the page and the layout. Is
this even possible?

Reply all
Reply to author
Forward
0 new messages