Skip to content

Why doesn't {{#with}} set context when it's nested? #3408

@ceremcem

Description

@ceremcem

Description:

I remember (but I'm unsure) that we could use {{#with foo}} to set the context to foo. It still works the same way, but not with nested structures. Why is that?

Versions affected:

1.4

Platforms affected:

Browser

Reproduction:

Ractive({
  el: 'body',
  append: true,
  data: {
    foo: {
    }
  },
  template: `
    <!-- context becomes foo -->
    {{#with foo as f}}
      <input value="{{f.hello}}" />
      {{#with f.bar as b}}
      	<input value="{{b.yay}}" />
      {{/with}}
    {{/with}}
  `,
  onrender: function(){
    console.log(JSON.stringify(this.get()))
  }
})

This code prints the expected output: {"foo":{"bar":{"yay":""},"hello":""}}

However, this simplified version produces an undesired result:

Ractive({
  el: 'body',
  append: true,
  data: {
    foo: {
    }
  },
  template: `
    <!-- context becomes foo -->
    {{#with foo}}
      <input value="{{hello}}" />
      {{#with bar}}
      	<input value="{{yay}}" />
      {{/with}}
    {{/with}}
  `,
  onrender: function(){
    console.log(JSON.stringify(this.get()))
  }
})```

Outputs: `{"foo":{"hello":""}}`

Is this behavior expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions