mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:30:01 +08:00
FIX: Lost outer context in #each
block in hbr (#28461)
Regressed 3.5 years ago in e80332a2bc
:P
This commit is contained in:
parent
b69a7ea824
commit
cee2605d88
|
@ -44,8 +44,8 @@ export function registerRawHelpers(hbs, handlebarsClass, owner) {
|
|||
}
|
||||
let list = get(this, contextName);
|
||||
let output = [];
|
||||
let innerContext = { ...options.contexts[0] };
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
let innerContext = {};
|
||||
innerContext[localName] = list[i];
|
||||
output.push(options.fn(innerContext));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import RenderGlimmerContainer from "discourse/components/render-glimmer-containe
|
|||
import raw from "discourse/helpers/raw";
|
||||
import rawRenderGlimmer from "discourse/lib/raw-render-glimmer";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { compile } from "discourse-common/lib/raw-handlebars";
|
||||
import {
|
||||
addRawTemplate,
|
||||
removeRawTemplate,
|
||||
|
@ -104,4 +105,20 @@ module("Integration | Helper | raw", function (hooks) {
|
|||
|
||||
assert.dom("span.bar").hasText(/^baz$/);
|
||||
});
|
||||
|
||||
test("#each helper preserves the outer context", async function (assert) {
|
||||
const template = `
|
||||
{{#each items as |item|}}
|
||||
{{string}} {{item}}
|
||||
{{/each}}
|
||||
`;
|
||||
addRawTemplate("raw-test", compile(template));
|
||||
|
||||
const items = [1, 2];
|
||||
await render(<template>
|
||||
<span>{{raw "raw-test" string="foo" items=items}}</span>
|
||||
</template>);
|
||||
|
||||
assert.dom("span").hasText("foo 1 foo 2");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user