Would it be considered best practice to use a single template that changes it’s output based on script values, or have multiple templates, and use the view to pick the correct one instead?
For example, in this underscope template:
<script type="text/template" id="SkillsetTemplate">
<div class='RegularMode <%= (skillset.get('InEditMode')===false)?'show':'hide' %>'>
</div>
<div class='EditMode <%= (skillset.get('InEditMode')===true)?'show':'hide' %>'>
</div>
</script>
I use a backbone model to bind against, and use the InEditMode attribute to pick which content to render.
Should I instead have a normal mode, and an edit mode template, and use the attribute on the model to pick the template ?
For background purposes, I am using backbone.js with underscore templates and an MVC3 backend.
I’d absolutely go with a second template. I’ll admit it may not be completely DRY but you never know, you may need the edit template to not look a bit like your non-edit one (in which case you aren’t repeating yourself).