spine / spine.app

Spine App generator
109 stars 26 forks source link

Jquery.tmpl.js can't render variables #5

Closed loicginoux closed 13 years ago

loicginoux commented 13 years ago

Hello, I am learning spine and node.js (both look really promising) and found this spine.app you had made. So to start, I generated the application structure with spine.app and incorporated your spine.todo application in the project. everything was fine except jQuery templating which couldn't render any variable:

        ##this.item being {name:'test',done:false}
        elements = $("#taskTemplate").tmpl this.item 

<script type="text/x-jquery-tmpl" id="taskTemplate">
    <div class="item {{if done}}done{{/if}}">
      <div class="view" title="Double click to edit...">
        <input type="checkbox" {{if done}}checked="checked"{{/if}}> 
        <span>${name}</span> <a class="destroy"></a>
      </div>
    </div>
  </script>

the result was:

<script type="text/x-jquery-tmpl" id="taskTemplate">
    <div class="item">
      <div class="view" title="Double click to edit...">
        <input type="checkbox" {{if done}}checked="checked"{{/if}}> 
        <span>undefined</span> <a class="destroy"></a>
      </div>
    </div>
  </script>

by comparing Jquery.tmpl.js from your spine.app project and the one from your spine.todos project I could spot a difference at the line 341:

.replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )

was replaced in the spine.app by:

.replace( /\$\{([^\}]*)\}/g, "undefined" )

I replaced the file by the one in your spine.todos project and worked fine. It must have interpreted it in some way. I just wanted to let you know about this issue. keep it up, you are doing an awesome work. Cheers

maccman commented 13 years ago

Yes, jQuery.tmpl made a weird decision (imho) and now doesn't execute ${} in the context of the data item. Either use the old one or ${$data.name} for the time being. I'm really hoping somebody will write a 'fixed' templating library someday.