marko-js / marko

A declarative, HTML-based language that makes building web apps fun
https://markojs.com/
MIT License
13.28k stars 641 forks source link

How to associate component controller with the template when using renderer (V4) #684

Closed wangwb closed 6 years ago

wangwb commented 7 years ago

Question

I'm trying to use renderer to render one of my template like this:

const template = require('./template')

module.exports = (input, out) => {
  // Do something else with the template, input or out
  template.render(input, out)
}

So is there a way I can associate my controller (component.js for example) to this certain template? Thanks a lot.

mlrawlings commented 6 years ago

An index.marko will automatically pick up a component.js in the same directory but for .marko files that have another name (like template.marko) the component file should have the same name prefix (like template.component.js).

See also: http://markojs.com/docs/components/#supporting-files