The Template – Getting Started

by Shea Frederick on March 2nd, 2007

I would suggest downloading the code used for this example here so you have something to work with. A working example can be found here.

Step 1, HTML for Your Template

The first step is pretty straight forward, its the HTML that will be used to format your data. Some keywords in curly brackets will be the placeholders for your data {id}, {url} and {text}. You could simplify this by using {0}, {1}, {2}, but naming your placeholders makes the code more readable.

Now we load the html template we just created into a template object (line 5), then compile the template for speed (line 6). Compiling the template is not required, but generally improves the speed.

Step 2, Adding Data to Your Template

In this next step we are going to append two rows to our data using the append method, as you can see the elements 'id', 'url' and 'text' correspond with placeholders in our template above.

Thats the basics of using the template, pretty simple, eh?

The Final Product

template-getting-started.js

template-getting-started-working.php

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS