BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.68k stars 340 forks source link

Style Attribute Wont Write #288

Closed billysmt closed 8 years ago

billysmt commented 8 years ago

I'm trying to write a style attribute based on what's in a json Object.

Example, {id: "fg-b36-64a", colWidth: "12", colOffset: "0", isActive: "false", style: "display: none;"}

Template piece is as follows:

< div class='col-sm-{{:colWidth}} col-sm-offset-{{:colOffset}} resize-group' id='{{:id}}' data-del-target='{{:id}}' data-handles='e' is-active='{{:isActive}}' style='{{:style}}'>

If I change style to something like ele-style, then the {{:style}} is written correctly, but when left as above it doesn't write anything. Not sure if I'm missing something or not but It seems like an issue.

BorisMoore commented 8 years ago

I'm not seeing that problem. When I run the page below, it works:

Can you test it? If it doesn't work for you, check your version of jsrender. And/or create a jsfiddle I can look at...

<div id="result">..loading</div>

<script id="myTmpl" type="text/x-jsrender">
<div class='col-sm-{{:colWidth}} col-sm-offset-{{:colOffset}} resize-group' id='{{:id}}' data-del-target='{{:id}}' data-handles='e' is-active='{{:isActive}}' style='{{:style}}'>what</div>
</script>

<script>
var tmpl = $.templates("#myTmpl");

var html = tmpl.render({id: "fg-b36-64a", colWidth: "12", colOffset: "0", isActive: "false", style: "display: none;"}); 

$("#result").html(html);

var test = $("#result").html(); // gives: '<div class="col-sm-12 col-sm-offset-0 resize-group" id="fg-b36-64a" style="display: none;" is-active="false" data-handles="e" data-del-target="fg-b36-64a">what</div>'

debugger;
</script>
billysmt commented 8 years ago

Hmm, Alright well looking into it a little deeper looks like the template is rendering correctly but I'm losing the style attribute after the fact somewhere in my JQuery. Sorry for the trouble. It's been a long couple days. Thanks for the help.