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!

Travis
  • 11
  • 1

2 Answers2

0

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
  • 17,827
  • 9
  • 58
  • 77
0

You should be able to do:

var templates = $.createTemplate($('templateList').html())._templates;

Then you can use templates and do:

$('#SOMEDIV').setTemplate(templates['PAGINATION'],templates);
&('#SOMEDIV').processTemplate(data);

I'm a js/jquery newbie so sorry if its not perfect. I'm loading it from a url using $.createTemplateURL instead of a text areas we