Re: Can't seem to be able to use variables in include statement

29 views
Skip to first unread message

Noah Kantrowitz

unread,
May 7, 2013, 5:12:03 PM5/7/13
to jad...@googlegroups.com

On May 4, 2013, at 4:20 PM, CyrilG wrote:

> I am trying to load a page with different templates. The template number is passed in the url, which i convert to a jade variable and pass it to my page as follow:
>
> extends ../layout
> block content
> div.page
> include template#{templateNumber}
>
> but I get an error "template#{templateNumber}. No such file or directory". If I replace it by " include template3", it works. It looks like jade processes the include before the variables . Any idea how I can fix that?

Includes are processed at template compile time, so you can't use them dynamically like that. You could maybe use a mixin or normal JS functions that happens to internally render another Jade template, but that comes with the associated performance cost. Overall it would probably be better to make each a top-level template just just extends a block in a shared template.

--Noah

signature.asc

Nami Doc

unread,
May 7, 2013, 7:49:45 PM5/7/13
to jad...@googlegroups.com
Include are compile-time, static.
Reply all
Reply to author
Forward
0 new messages