Open loppear opened 7 years ago
Clarifying question: in point#3 "decompose the template..."
I was thinking this was done with include
calls in the parent EJS template. How is the render('...')
example you give here different?
@ScottMaxson render is our preferred alternative for include
that lets other modules / end-user replacement of the template (it's a template name rather than a relative path).
👍 let's definitely add into the docs as well.
Goals
default()
when registering)render()
) when wrapping/overriding. (register the base name as well)render()
)Approach
For reusable modules to provide a base template implementation
users-login
templater.default().template('path/users-login.ejs', 'page')
render('users-login-form-fields')
calls so that the partial templates can be overridden rather than overriding the whole thing.Additionally, for modules that provide default functionality that may be used repeatedly (per model, say), we typically construct a specific name and register the default implementation under that name - this template doesn't exist but can be implemented by an end-user:
templater.default().template('path/web-controller-list.ejs', 'page', 'yourmodule-yourmodel-list')
Good practice here is to also register the template once at the base name,
web-controller-list
, so that an actual implementation ofyourmodule-yourmodel-list
canrender('web-controller-list')
to simply wrap the base implementation (and/or any specific overridden template implementations).Questions
appname-module-template
before falling back tomodule-template
?include
be discouraged or only for reusable modules [Luke: I think include is fine in end-use templates, rather than needing to add all templates into the registered namespace]