ect
ect copied to clipboard
Providing context to a partial prevents other included partials from accessing that context
Scenario 1: without passing context to a partial
bar.ect
<% include 'foo' %>
<%- JSON.stringify @, null, 2 %>
foo.ect
<% @foo = 'foo' %>
page.ect
<% include 'bar' %>
output
{
"foo": "foo"
}
Scenario 2: passing context to a partial
bar.ect
<% include 'foo' %>
<%- JSON.stringify @, null, 2 %>
foo.ect
<% @foo = 'foo' %>
page.ect
<% include 'bar', { baz: 'baz' } %>
output
{
"baz": "baz"
}
Here, I would expect the context to be mixed in, and the output to be:
{
"foo": "foo",
"baz": "baz"
}
For anyone else experiencing this issue, my workaround is to pass @ to the included partial:
bar.ect
<% include 'foo', @ %>
<%- JSON.stringify @, null, 2 %>
output
{
"foo": "foo",
"baz": "baz"
}