views:

53

answers:

1

Using jTemplates, it is possible to composite templates like so...

<textarea id="templateList" class="template"><!--

  {#template RESULTS}
    This a template for generating a list of results
    {#include PAGINATION root=$T}
  {#/template RESULTS}

  {#template PAGINATION}
    This is a template for generating pagination through the results
  {#/template PAGINATION}

--></textarea>

However there are times when it would be handy to be be able to composite completely different templates. For example, I have a lot of different types of lists, each of which has a distinct template. Using the method above, I am forced to keep repeating the same chunk of code for pagination over and over in each of my templates for different lists.

I would much rather do something like the following...

<textarea id="templateList" class="template"><!--
  This is a template listing results
  {#some kind of call to templatePagination}
--></textarea>

<textarea id="templatePagination" class="template"><!--
  This is a template for generating pagination
--></textarea>

Does anyone know if such a thing is possible and, if so, how to go about it?

Thanks!

A: 

You can append all your needed templates together when you setTemplate if you have no template refrence.

$(container)
   .setTemplate($('templateList').html() + $('templatePagination').html())

or you can createTemplate and pass the reference as a include

var t = $.createTemplate($('templatePagination').html());
$(container).setTemplate($('templateList').html(), t._templates)
Glennular