jonschlinkert / template

Render templates from any engine. Make custom template types, use layouts on pages, partials or any custom template type, custom delimiters, helpers, middleware, routes, loaders, and lots more. Powers Assemble v0.6.0, Verb v0.3.0 and your application.
https://github.com/jonschlinkert
MIT License
52 stars 7 forks source link

Post Render middleware and cloned template object. #14

Closed doowb closed 9 years ago

doowb commented 9 years ago

This section of code is what I'm referring to here:

This makes it so users that want to modify something else in a postRender middleware can't because the changes only affect the cloned object and are lost. The common case for this is changing path after rendering.

Should we allow changing other properties in postRender? I think the better way to do it is in preRender since the properties will be updated for use during the rendering process.

jonschlinkert commented 9 years ago

This makes it so users that want to modify something else in a postRender middleware can't because the changes only affect the cloned object and are lost.

What are the common use cases for passing the cloned.content back to the caller? Either way I think we should ensure that middleware can modify properties post render.

doowb commented 9 years ago

Passing the cloned.content is the actual value returned when doing either var content = template.render() or template.render(function (err, content) { ... });.

We're going to have to basically do a "clone" on the cloned object to get all the changed properties to sync with the template object and make sure that the content doesn't change on the original template object, but still return the cloned content string.

Actually, this might not be an issue now that the templates are pre-compiled. Cloning was added before that was in there to ensure the partials can be rendered multiple times. Now that they get pre-compiled, the original template.content can be updated and it won't be affected because the compiled piece will still be there on template.fn.

I'll try out some things and let you know.

jonschlinkert commented 9 years ago

That's exactly what I was wondering, about the compiled functions. thanks for clarifying