Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Template - Executing JS code inside the template

I am trying to learn more about jQuery templates but cant seem to execute any JS calls inside the template.

<script id="log-item" type="text/x-jquery-tmpl">
 {{if title.length }}
   <h3 style="padding-bottom:5px;">${ title }</h3>
 {{/if}}
 objectToString(${ detail });
</script>

Note that my objectToString() function is never called, just rendered out as a string. I tried wrapping it in {{ }} on a whim but no luck. Anyone out there who can help?

like image 536
Anthony Webb Avatar asked Jan 19 '11 07:01

Anthony Webb


1 Answers

Anthony, you can. The method your calling needs to be inside a template tag like so:

<script id="log-item" type="text/x-jquery-tmpl">
 {{if title.length }}
   <h3 style="padding-bottom:5px;">${ title }</h3>
 {{/if}}
 <p>
    Detail: ${ objectToString( detail ) }
 </p>
</script>
like image 62
Harborhoffer Avatar answered Nov 15 '22 12:11

Harborhoffer