You could use three separate templates:
<script id="top" type="text/x-handlebars">
<section class="single-column">
...
</section>
</script>
<script id="middle" type="text/x-handlebars">
<section class="two-column">
...
</section>
</script>
<script id="bottom" type="text/x-handlebars">
<footer class="single-column">
...
</footer>
</script>
and some CSS:
.two-column {
width: 50%;
...
}
.single-column {
width: 100%;
...
}
to sort out the widths. Note the switch to class attributes for the styling, that avoids possible duplicate id
s. Then chop the array into three pieces in JavaScript:
var top = images.shift();
var bottom = images.pop();
// the middle is left in images.
Demo: http://jsfiddle.net/ambiguous/F3Acm/1/
You could also use the same technique but leave everything in one template:
<script id="t" type="text/x-handlebars">
<section class="single-column">
<!-- do things with {{top}} in here -->
</section>
<section class="two-column">
<!-- do things with {{middle}} in here -->
</section>
<footer class="single-column">
<!-- do things with {{bottom}} in here -->
</footer>
</script>
and then handle the compiled template three variables:
var t = Handlebars.compile($('#t').html());
var h = t({
top: top,
middle: images,
bottom: bottom
});
Demo: http://jsfiddle.net/ambiguous/yD7wF/
You could also use partials. The four templates would look like:
{{> top}} {{> middle}} {{> bottom}}
Then register the partials and fill in the template:
Handlebars.registerPartial('top', $('#top').html());
Handlebars.registerPartial('middle', $('#middle').html());
Handlebars.registerPartial('bottom', $('#top').html());
var t = Handlebars.compile($('#t').html());
var h = t({
top: first,
middle: images,
bottom: last
}));
Demo: http://jsfiddle.net/ambiguous/LLqY9/
Which approach you use depends on which one fits best with your situation.