glimmerjs / glimmer-inline-precompile

MIT License
3 stars 1 forks source link

Feature request: inline glimmer component templates #2

Open jamesarosen opened 7 years ago

jamesarosen commented 7 years ago

Glimmer doesn't seem to support inlining component templates. I've tried

import Component from '@glimmer/component';
import hbs from '@glimmer/inline-precompile';

export default class Welcome extends Component {
  layout = hbs`<div><h1>Welcome to Glimmer!</h1></div>`
}

and variants thereon.

The issue seems to be that the rendering environment doesn't have access to the component instance, so it can't look up the compiled template. This will likely require coordination between this project and glimmerjs/glimmer.js.

yads commented 3 years ago

This would also be great for certain testing scenarios.

privatenumber commented 3 years ago

This should be possible with something like this:

import templateOnly from '@ember/component/template-only';
import { setComponentTemplate } from '@ember/component';
import { hbs } from 'ember-cli-htmlbars';

export default setComponentTemplate(
    hbs`<div>inline template!</div>`,
    templateOnly(),
);

setComponentTemplate RFC