Providing routes with controllers and templates with addon v2

Hey everyone, I’m trying to write a new addon v2 that provides routes with controllers and templates. I made this update in the rollup.config.mjs file:


 addon.appReexports([
      'components/**/*.js',
      'helpers/**/*.js',
      'modifiers/**/*.js',
      'services/**/*.js',
      'utils/**/*.js',
      'controllers/**/*.js',
      'routes/**/*.js',
      'templates/**/*.js',
    ]),

and everything works fine, but the template does not have the context set to the controller instance.

Does anyone know how do I set the template context to the controller value? In a proper app it is done automatically, but in this case, it does not work well

1 Like

I did some debugging and it looks like Embroider, compiles my template to:

import templateOnly from '@ember/component/template-only';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';

var TEMPLATE = precompileTemplate("....");

var access = setComponentTemplate(TEMPLATE, templateOnly());

export { access as default };
//# sourceMappingURL=access.js.map

I assume that templateOnly() should be replaced with some reference to my controller, or am I missing something?

if you are supporting ember-source 6.3+ templates can be components, but you’d access the controller via @controller

prior to that, you’d want

to make defining a component for a template-route more ergonomic

oh! you are right! it worked perfectly. I somehow missed this detail in the changelogs :smiley:

1 Like