Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

12/04/2009 The jTemplates plugin for jQuery – Keep inline templates from being misinterpreted
Posted by Joel Varty

I love the jTemplates plugin for jQuery.  It works great and I’ve had very little trouble working with it when I put my templates in separate files.  This ensures that the browser does re-interpret the html for the template and re-arrange the elements.  This happens mostly with tables in IE and Webkit browsers where you want to repeat the rows of the table.  You’ll see what I mean in a moment.

Take a template like the following:

<table>    
    <thead>
        <th>Date</th>
        <th>Title</th>
        <th>Count</th>
    </thead>
    <tbody>
        {#foreach $T as o}
            <tr>                                
                <td>{$T.o.CreatedOn}</td>
                <td>{$T.o.Title}</td>
                <td>{$T.o.Count}</td>
            </tr>
        {#/for}
    </tbody>    
</table>

 

This works great if I put the template in it’s own html or text file, but not if I embed it in a <div>. 

Why?  Well, the {# foreach} and the {#/for} lines in the template are NOT interpreted as being part of the <table> element, and so that text ends up being placed in the DOM as text elements either before or after the table.

The way around this is simple – just place your template in a <textarea> instead of a div.  Then you can use $(“#elementID”).val() to grab the literal text (which isn’t interpreted into the DOM as anything but text), and all should be good.

More later - joel

Read the complete post at http://weblogs.asp.net/joelvarty/archive/2009/12/04/the-jtemplates-plugin-for-jquery-keep-inline-templates-from-being-misinterpreted.aspx

« Back to Blog Main Page |

0 Comment(s)

Leave Comment

Name:
Comment:  
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270

From Our Blog

02/09/2010
Amazon S3 – Now with Versioning! Posted by Joel Varty
02/02/2010
01/19/2010
411 Length Required in Firefox 3 Posted by Andre Small
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy