Reputation: 171
I have this piece of code.
<h1>Title</h1>
<section class="suggestions-section">
<h2></h2>
<div class="special-suggestions">
{{#each suggestions}}
<fieldset>
<legend>{{header}}</legend>
<img src="{{src}}" alt="">
<div class="placeholder-buy"></div>
</fieldset>
{{/each}}
</div>
</section>
Is it possible to compile this code and put h1 in one DOM element and other things in other?
const mainContent = $('#main-content');
const header = $('#header');
//compile template
mainContent.prepend(template(data));
header.append(template(data))
Can I do this using one template or I have to make two?
Upvotes: 0
Views: 23
Reputation: 1395
Why is your title not part of your template? (I should expect it to be dynamic as well.)
You can use 2 different templates in separate files as you say.
You can instantiate template
method twice:
var template = Handlebars.template(src);
var templateSecond = Handlebars.template(src2);
Take a look at Partials. kinda like custom filters. But can do the job.
Upvotes: 1