How can an external jQuery templates be loaded
Asked Answered
R

2

7

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.

Refresher answered 1/6, 2011 at 12:52 Comment(2)
Why not just copy all the separate template code into one file?Cushion
would be sweet if templates could be fetched as a html resource just like css and image files.Bookish
S
-1

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");
Sledge answered 13/12, 2014 at 14:39 Comment(0)
C
-2

you can use the src attribute, like this:

<script src="/my/templates.html" type="text/x-jquery-tmpl"></script>
Clown answered 30/11, 2014 at 5:9 Comment(1)
it is not working :( also no exception on javascript consoleIaea

© 2022 - 2024 — McMap. All rights reserved.