ect icon indicating copy to clipboard operation
ect copied to clipboard

Providing context to a partial prevents other included partials from accessing that context

Open paulyoung opened this issue 11 years ago • 1 comments

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"
}

paulyoung avatar Jul 30 '14 20:07 paulyoung

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"
}

paulyoung avatar Jul 30 '14 20:07 paulyoung