How to dynamically create a Blaze Template from database string

Viewed 89

I'm using Meteor's blaze viewmodel.org, a couple of years back I found a way to save blaze templates and viewmodels in database and render them dynamically, But unforuntatley I lost the code and I could not recreate this as it was not documented anywhere.

How do I recreate the same behavior?

Sample database

db.templates.insert({
    name: "templateName",
    blaze: "Hello {{viewmodelNameHelper}}",
    viewmodel: " { onCreated() {console.log('oncreated hook')}, viewmodelNameHelper(){return 'Your Name!'} }"

});

viewContainer.html

<template name="viewContainer">
 {{ myRenderTemplateHelper  }}
</template>

viewContainer.js

Template.viewContainer.viewmodel({

  onCreated(){
    // subscribe for template from database
  },
  myRenderTemplateHelper(){
     // required code here
  } 
})

Output

Hello Your Name!

Please note that Template.dynamic and Blaze.renderWithData() won't help as I need to attach the dynamic viewmodel object to the created template instance. where all the viewmodel helpers and events are reactive.

I also tried to do the same using react but I couldn't find enough resources on that?

0 Answers
Related