Closed lucashpandolfo closed 9 years ago
I'm afraid the documentation is wrong. There's no support for that atm. I've tried a fix, but template includes are resolved at compile time (compile-template), so I think a quick patch would be to allow to pass arguments to compile-template function, but I'm not sure that would be very useful, doesn't look very dynamic. Or would that be enough for your purposes?
The idea is:
(compile-template* "template.djula" :t1 "include.djula")
and then: {% include t1 %}
although that's quite static because it's at compile time.
Something like render-time inclusion would be more flexible, but I think much more difficult to implement because of how Djula is implemented.
Wait...maybe I will be able to implement this at render time.
Ok. I've pushed an implementation of this.
(render-template* template nil :t1 "myincludetemplate.djula")
Can you pull from master and test?
It's not really a big deal. My code is something like:
(defroute new-item "/new/:type" (&key type)
(let ((form (assoc type '(("t1" . "f1.dtl")
("t2" . "f2.dtl")) :test #'string-equal)))
(if form
(render #P"new.dtl" `(:form ,(concatenate 'string "forms/" (cdr form))))
(throw-code 404))))
And then, new.dtl:
{% extends "layouts/default.dtl" %}
{% block content %}
...
...
{% include form %}
...
...
{% endblock %}
And then f1 and f2 just have a form.
But i could change it so f1 and f2 extends from a 'layouts/new-item' template avoiding the include.
Ok. I can confirm it is working now. Thanks.
The manual (http://mmontone.github.io/djula/doc/build/html/tags.html#include) says: "The template name can either be a variable or a hard-coded (quoted) string, in either single or double quotes.". Using the template
I get:
If i change it to:
I get:
Seems like
include
is expecting a string only (not a variable). Is there another way to include a template using variables?