Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning a fragment from a section helper doesn't work #647

Open
phillipskevin opened this issue Dec 6, 2018 · 2 comments
Open

Returning a fragment from a section helper doesn't work #647

phillipskevin opened this issue Dec 6, 2018 · 2 comments

Comments

@phillipskevin
Copy link
Contributor

In 3.0, this would create a fragment containing <p>this is foo</p>:

stache.addHelper("foo", (options) => {
  return stache("<p>this is foo</p>")();
});

const frag = stache(`
    {{# foo() }}
      <p>this is NOT foo</p>
    {{/ foo }}
`)();

document.body.appendChild(frag);

...in 4.0, it only contains <p>this is NOT foo</p>.

3.0 version: https://codepen.io/kphillips86/pen/eQwjZz
4.0 version: https://codepen.io/kphillips86/pen/EOBpVZ

cc @mjstahl.

@justinbmeyer
Copy link
Contributor

I'm not sure this is necessarily wrong ... foo() is returning a truthy value, so it makes sense that <p>this is NOT foo</p> would then be readered as if foo() returned a true or 1.

We could change this to make # VALUE do something different if given a fragment.

@phillipskevin
Copy link
Contributor Author

Yeah, I can’t think of a situation where you would want to return a fragment and not have it rendered.

Alternatively, you can make this work by setting options.metadata.rendered = true; in the helper. This is what stache does internally when you call options.fn() or options.inverse() so it knows to display the fragment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants