How can i make Wysiwyg editor which has html tags and save it in the database so that i can send emails using that template?

how can i make Wysiwyg editor which has html tags and save it in the database so that i can send emails using that template ?

Importantly It needs to be able to grab the values of the key value from the database, so that the values can be replaced.

for example, if the user is working on an object that has

{
ownername: "Sam Hargett’,
lastContact_date: “23 March- 2017”,
Price: “2,000”
}

so template will save this info like

Hello {{ownername}}, my name is {{ user_logged_in}} . We talked with you on {{lastContact_date}}. We discussed about the price of your truck to be {{Price}}. Is it still avaiable ?


when generating email, the body content of the html should be replaced with real data not the variables.

Anybody has done stuff like this before ?

Do you mean you want to create actual Blaze templates, with Spacebars and such? Or just create HTML emails?

If you just want HTML emails, it shouldn’t be difficult, there are many free editors you can use. I did a lot of searching and comparing, and my favorite is TinyMCE. The Meteor package for it is called teamon:tinymce

Read the tutorial for the editor on how to get the output from it. After that you just do like you do with regular strings :slight_smile:

Hi heteby, I just updated my question, Could you please recomend, what woud be the best option ?

fyi: I’m using React for frnt end. and in a month moving to Appollo + graphql.

Hmm, you could probably dig around for a templating package that does this.
However, maybe you could just do a regex string replace? Something like this:

var HTML = "Your template with {{name}} {{printPrice}}";
var context = {
  name:'John',
  price:500,
  printPrice:function(){
    return '$' + this.price;
  }
}

HTML.replace(/{{.*?}}/g,function(key){
  var stuff = context[key.slice(2,-2)];
  if(typeof stuff == 'function'){
    return stuff.call(context);
  } else {
    return stuff;
  }
});

Or actually just use Handlebars, it looks very simple to implement! :slight_smile:
http://handlebarsjs.com/

Handebars is nice, but not the best option… we have to figure out the best option.

What’s wrong with Handlebars? Seems like it would do everything you wanted?

I’ll try to implement this and let you know…

Will this code replace all the {{ tags }} saved in the db before the email’s html body is flushed out ?