-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue in include() functionality #254
Comments
@morandd thanks for opening this issue!
Are you sure this is the case? Though this should happen (according to documentation 😅), looking at the code, it doesn't seem like the data is merged with |
Yes, I think I can confirm this is a bug. Here's a test case:
which uses the header
And we execute it using a simple script
The If the merge operation happened correctly then header.eta should have access to
|
a workaround is to add {it} to every child include() call. For example:
this way the child partial |
@morandd thanks for the thorough details and tests. This begs the question: do we want to automatically have partials inherit I'll open up the discussion on Discord. |
I've just started porting an EJS project to ETA and this is causing quite a lot of extra code. The docs state that: "we can also pass in data that will be merged with But, as noted above by Ben, this is not in fact implemented at all. Oddly, the At the moment, I am basically writing something like: <%~ include('@template', Object.assign({}, it, { extra: 123 })) %> almost everywhere (out of laziness - because I need a handful of global variables in almost all partials). This is leaving me with very messy template files. It would be nice to either have a third parameter that tells the function to use the global data value, or a separate set of functions that work this way: <%~ include('@template', { extra: 123 }, true) %>
// or
<%~ includeData('@template', { extra: 123 }) %> I prefer the second approach because it allows seemless passing without an empty object if there is no extra data to pass: <%~ include('@template', {}, true) %>
// vs
<%~ includeData('@template') %> Of course the |
@paul-norman I understand where you're coming from. However, there is a faster way to merge data. It seems like |
Describe the bug
Nested includes() do not pass data to children templates by default.
If you use:
<%~ include("./child.eta") %>
then child.eta will not receive any data available at the parent. But, if you provide an empty object as the second parameter to include, like this:
<%~ include("./child.eta", {}) %>
then the child does inherit access to the parents data.
The documentation implies that the second data parameter is optional and provides extra variables that will be merged with "it". But the observed behaviour is that the second parameter is undefined and thus overwrites "it".
I think the issue arises as line 23 of compile-string.ts.
I suggest that nested child includes()'s should have access to the parent's data by default as this makes sense intuitively and is the behaviour of EJS.
Thanks for your contribution to this. Deno needs a good templating engine.
The text was updated successfully, but these errors were encountered: