Should I use parameters in template scripting to control the output, or a separate specialized template?

Posted by asawyer on Stack Overflow See other posts from Stack Overflow or by asawyer
Published on 2012-03-28T17:26:31Z Indexed on 2012/03/28 17:30 UTC
Read the original article Hit count: 237

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about templates