baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
626 stars 70 forks source link

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

Open paulyoung opened 10 years ago

paulyoung commented 10 years ago

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 commented 10 years ago

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