I found this page to search on the same issue, but in a different context, so I thought that for posterity my solution (read: workaround):
I would like to surround my inclusion with a large context pulled from a variable, for example. (Simplified):
- var templates = page + '/templates/' - var headid = page + 'head' - var imgsrc = '/images/' + page div(id=headid) h1 #{page} img(src=imgsrc) div(id=page) include templates
Since this does not work (Jade does not support dynamic inclusions, as noted by fancy), I am hybridized with mixin:
(Edit is a bit more elegant than my previous workaround :)
mixin page1 include page1/templates mixin page2 include page2/templates ... - for (var i = 0; i < 3; i++) - var page = 'page' + i - var headid = page + 'head' - var imgsrc = '/images/' + page div(id=headid) h1
My previous answer:
mixin templates(page) - var headid = page + 'head' - var imgsrc = '/images/' + page div(id=headid) h1 #{page} img(src=imgsrc) +templates('page1') #page1 include page1/templates/ +templates('page2') #page2 include page2/templates/ ...
It's not elegant, and it won't work if you need to include more than a few things this way, but at least the Jade part is dynamic.
Frijol Mar 12 '14 at 22:37 2014-03-12 22:37
source share