问题
I'm specifically trying to do this client side but it it can only be done server side I will use Meteor.call to return the compiled template as a string via DDP/Ajax.
My end goal is to dynamically create new templates (HTML, events, helpers, etc) at runtime. And then sometimes replace existing templates with updated ones.
回答1:
The compilation of templates is done on the server, see
https://github.com/meteor/meteor/tree/devel/packages/spacebars-compiler
I don't think you'd want to do this on the client because then each client may have different local templates and display things differently. You would have to send the templates to the server anyway so that other clients could get them updated as well. Same thing for helpers, etc.
Are you sure that you can't achieve this by defining some templates that can be shared across clients and then updating the data context? It seems you are trying to create some way for clients to produce new templates for the app, but you can accomplish this by having some sort of structured data that nests existing templates together to create custom views.
来源:https://stackoverflow.com/questions/24729649/what-core-meteor-methods-can-i-call-to-compile-a-new-template