Answer the question
In order to leave comments, you need to log in
Where to store HTML and CSS for JS?
For example, there is a bootstrap alert:
<div class="alert alert-success" role="alert">...</div>
<script id="entry-template" type="template">
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
</script>
Answer the question
In order to leave comments, you need to log in
Well, if you really really want to do without a template engine, then you can do this: jsfiddle.net/ph2xnbfv/1
var html =
'<div class="entry">' +
'<h1>{{title}}</h1>' +
'<div class="body">' +
'{{body}}' +
'</div>' +
'</div>';
var title = "Vasya";
var body = "Pupkin";
var result = html.replace("{{title}}", title);
result = result.replace("{{body}}", body);
console.log(result);
Let me ask you: why don't you want to use template engines?
It's just that you give markup in a script as an example - this is already the beginning of using template engines :)
If you are confused by the weight of template engines, but you don't need logic in templates (and you just need to replace values), then you can use something very lightweight: https:// github.com/felixexter/tmpl.js
var html = $('#entry-template').html().tmpl({
title: 'My title',
body: 'My body'
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question