Hide the template code
i'am working on a little javascript library, that uses the lovely jquery-tmpl engine. I would like to avoid forcing the user to paste the nec开发者_开发百科essary templates into his/her html (or to be confronted with the template code at all for that matter).
So my question is: Is there a way to hide my template code, preferably in my js file, as I understand, the script-tags are necessary (if only in order to be able to select it with jquery). The only thing I found so far is putting the templates in external file like here but it is not really what i want. thanks$.template('yourTemplateName', 'yourTemplateCode');
From http://api.jquery.com/jQuery.template/
This method compiles the markup in the template parameter as a named template, which can be referenced using the string specified in the name parameter.
The return value is the compiled-template function.
Example: Create a compiled template associated with the name "summaryTemplate" and then reference it by name for rendering:
// Convert the markup string into a named template
$.template( "summaryTemplate", "<li>${Name}</li>" );
function renderList() {
// Render the movies data using the named template: "summaryTemplate"
$.tmpl( "summaryTemplate", movies ).appendTo( "#moviesList" );
}
精彩评论