Jinja replace values in text template

Greetings friends
I have created a module where I need to populate a text editor field from a template.
I have achieved it, but I also want 2 fields of the form to be replaced in the text and I do not get it.
The code of the .js is the following:

frappe.ui.form.on(‘Contrato Marco’, {
refresh: function(frm) {
},
planti_cm: function(frm) {
frappe.call({
“method”: “frappe.client.get”,
args: {
doctype: “Texto Contrato Marco”,
name: frm.doc.planti_cm
},
callback: function(data) {
frappe.model.set_value(frm.doctype,
frm.docname,“txt_cm”,data.message.texto_contrato)
}
})
}
});

Attached also illustrative image, I hope someone tells me what to do to get the replacement of the fields.

regards

Fernando

Hi @Fernando_Sanchez1,

to my knowledge the text field will not convert Jinja contents. But, when you insert the template in your function, why not simply use str.replace, something like this:

(...)
callback: function(data) {
  var text = data.message.texto_contrato;
  text = text.replace("{{ name }}", cur_frm.doc.name);
  text = text.replace("{{ cliente }}", cur_frm.doc.customer_name);
  frappe.model.set_value(frm.doctype, frm.docname, “txt_cm”, text)
}

Hope this helps.

I thought that yes, as in the Terms and Conditions of the Purchase Order it does. I wanted to do it in the same way but I did not achieve it.
I will try doing as you suggest and I will write the result.
Thank you very much.

I already achieve it, I thank lasalesi, but I still disagree, it seems an “artificial” solution, every time I add a field to replace I must modify the .js file.
I would have liked to do it in the same way as it is done in “Terms and Conditions” in the purchase order. I just define the field {{fieldname}} in the template and the system replaces it automatically. If someone can give me the route I will be grateful.

Cordially

Fernando

Hola Fer.
Did you find any solutions for this?