I'm using underscorejs function _.template()
to render html on client side. I found that in many examples, the templates are placed in some <script type="text/template" id="id">
on the page, and using $('#id')
to get the templates. like this:
<script type="text/template" id="id">
<div class="form-group row">
<label for="nickname" class="col-sm-2 control-label text-right">nickname</label>
<div class="col-sm-10"><span><%= data.subscriber.nickname %></span></div>
</div>
<div class="form-group row">
<label for="sex" class="col-sm-2 control-label text-right">sex</label>
<div class="col-sm-10"><span><%= data.subscriber.sex %></span></div>
</div>
<div class="form-group row">
<label for="country" class="col-sm-2 control-label text-right">country</label>
<div class="col-sm-10"><span><%= data.subscriber.country %></span></div>
</div>
</script>
I try build a block to hold these tags, but drupal will break it, lost some tags eventually.
My solution right now drives me crazy: save the template as one line string or concat multiline strings with \
in js.
I really need a better idea. Thanks.
UPDATE: I found a better idea, using coffee script raw string. From External template in Underscore
'js'
to'script'
, but it will not happen in 7, I doubt it could happen in 8, and it's long wait for 9. So all we can get is someone hacking around this limitation. I'd like to see it happen.