How to render template by name (name has string type)?
pikhovkin opened this issue · 7 comments
pikhovkin commented
How to render template by name (name has string type)?
I need to pass the name of the template as a string.
Example:
<script type="text/monkberry" id="Template">
<h1>Hello {{ name }}!</h1>
</script>
var view = Monkberry.render('Template', document.body); // <-- 'Template'
view.update({name: 'World'});
pikhovkin commented
@antonmedv, example, please
antonmedv commented
Read the docs
pikhovkin commented
I didn't find this in docs. I would not ask if it was there.
antonmedv commented
Define template with text/monkberry.
<script type="text/monkberry" id="component">
<h1>
Hello, {{ name }}!
</h1>
</script>
And you now can get access to component template.
var view = Monkberry.render(component, document.body);
DeLaGuardo commented
@pikhovkin templates in monkberry-standalone evaluated in global scope. So you can render them with little trick: var view = Monkberry.render(window['Template'], document.body);
If you need to identify them by strings
pikhovkin commented
@DeLaGuardo, exactly! Thanks!