Closed chaitanyagupta closed 6 years ago
Ok. I would call this "parameterized includes". I think it makes sense. I'll think about it more later.
What about using this syntax?:
{% include "user-ref.html" :user record.creator :other-argument 33 %}
Looks more consistent with the syntax we have in other part of Djula, for rendering templates for example.
Yeah this makes a lot more sense.
On Fri, 1 Jun 2018 at 7:10 PM Mariano Montone notifications@github.com wrote:
What about using this syntax?:
{% include "user-ref.html" :user record.creator :other-argument 33 %}
Looks more consistent with the syntax we have in other part of Djula, for rendering templates for example.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mmontone/djula/pull/45#issuecomment-393884003, or mute the thread https://github.com/notifications/unsubscribe-auth/AACMhOPjmpwtQDRPXR64TE-ih2HV9YrBks5t4URkgaJpZM4UVn_L .
-- https://chaitanyagupta.com https://lisper.in https://twitter.com/chaitanya_gupta
Ok. If you implement that, and maybe add some test (parse a template with a parameterized include and check the result (see Djula tests for inheritance, etc)), I'll be happy to integrate.
Ok, I will close this PR and open a new one.
What this branch does?
Adds experimental bindings for the
include
template tag, which extends*template-arguments*
when the included template tag is rendered.e.g.
{% include "user-ref.html" (user record.creator) %}
will binduser
to the value ofrecord.creator
while rendering the templateuser-ref.html
.Why is it required?
I want to use an included template at multiple places in the same document. However the context needs to be different at each of these places. I couldn't find any existing functionality that would allow me to do this, hence this patch. (Please correct me if this could be achieved in another way).
I'll explain what I need with an example:
First, the parent template (
record.html
):Notice that
user
is bound to different values above.Next, the included template (
user-ref.html
):If I run the following Lisp code:
The expected output is:
Final Note
I hope I have demonstrated the need for this functionality with the example above. In case this could be accomplished with an existing tag, my apologies.
Finally, this patch was just meant to show the functionality I am hoping to see in djula. I am certain that things like syntax, etc. may not be to the maintainers' liking. I'd be happy to make any changes.