Matthew
Matthew

Reputation: 11623

How can an external jQuery templates be loaded

I have a large number of jQuery templates taking up space in my <head> section ("text/x-jquery-tmpl"). I would like to move these tags to an external file. I was hoping I could do something like <link href="/templates.html" type="section"/> but I realize that's not what link is meant for, and indeed it doesn't seem to work.

How should I do this? I could look into a loader (might be hard to find an html loader though), but that feels like overkill Could just be that I have no other choice but to include the tags in my page.

Upvotes: 7

Views: 1747

Answers (2)

Roumelis George
Roumelis George

Reputation: 6746

You could use a separate file for each template and then use jQuery's load function and inject each template where you want to use it. For example:

$('body').load("templates/template1.html");

Upvotes: -1

ChrisA
ChrisA

Reputation: 293

you can use the src attribute, like this:

<script src="/my/templates.html" type="text/x-jquery-tmpl"></script>

Upvotes: -2

Related Questions