Friend, the best thing to do is to automate the pre-compilation process, if you want to know how to do it using Grunt, you can read more about this link;
you can also catch the recover script from the script by accessing the source property through the source property, for example, if you do this:
console.log(_.template($('#tpl-template').html()).source)
you will possibly have the following exit:
function(obj){
var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
with(obj||{}){
__p+=' Meu nome é <b>'+
((__t=( nome ))==null?'':__t)+
'</b>\n';
}
return __p;
}
then basically you would only need to have the following code in a separate JS file:
var templates = {};
templates.meuNome = function(obj){
var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
with(obj||{}){
__p+=' Meu nome é <b>'+
((__t=( nome ))==null?'':__t)+
'</b>\n';
}
return __p;
}
in your main script, you would just have to use the templates.meuNome({nome: 'Wallace'})
, without the need to have the tag script#tpl-template
on the page.
finally a small example with a utility to generate the Scripts:
var textTemplate = document.getElementById("textTemplate");
var textPreCompiled = document.getElementById("textPreCompiled");
var txtNomeTemplate = document.getElementById("txtNomeTemplate");
var btPrecompilar = document.getElementById("btPrecompilar");
btPrecompilar.addEventListener("click", function (event) {
var tmplSource = textTemplate.value;
var template = _.template(tmplSource);
textPreCompiled.value = "var " + txtNomeTemplate.value + " = " + template.source;
});
textarea {
width: 100%;
height: 240px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<textarea id="textTemplate">
Meu nome é <b><%= nome %></b>
</textarea>
<label>
Nome template:
<input id="txtNomeTemplate" type="text" value="tplTemplate" />
</label>
<input id="btPrecompilar" type="button" value="PreCompilar Template" />
<textarea id="textPreCompiled">
</textarea>
<script type="text/template" id="tmplNome">
</script>
Any special reason why I took a -1? Was my question so stupid? kkkkkkkk
– Wallace Maxters
You want to make a new Angularjs. Ps1 - I’m not the one who said no. Ps2 - You ask many questions, must be why the -1. Ps3 - I don’t know the answer. Ps4 - It has already begun national manufacturing, will lower the price.
– Diego Souza
I don’t understand PS4.
– Wallace Maxters
Many questions is not a criterion for negative (I’m glad my wife doesn’t give me negative votes) kkkkkkkk
– Wallace Maxters
http://olhardigital.uol.com.br/noticia/ps4-produzido-no-brasil-ja-esta-a-venda-por-r-2-6-mil/51846
– Diego Souza
Sopt’s criteria is not, but it may be someone’s criteria.
– Diego Souza
Ps4 was a joke... You have good mood
– Wallace Maxters
Let’s go continue this discussion in chat.
– Wallace Maxters
So you mean the angle already does it? Thanks for the tip, I just got to it now
– Wallace Maxters