Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access to contents of script tag with src attribute (template including) [duplicate]

Possible Duplicate:
How to outsource a template js to a different file when using Handlebars.js

I'm using handlebears. They recommend to include templates in documents body like this:

<script id="entry-template" type="text/x-handlebars-template">
     template content
</script>

I want to use template contents through src attribute and store my templates (mass of) in separate files.

<script src="/path/to/my.template" id="entry-template" type="text/x-handlebars-template"></script>

Question is how to access co contents of it?

$('script#entry-template').html() //returns ""
$('script#entry-template').text() //returns ""
like image 960
demon.mhm Avatar asked Nov 05 '12 17:11

demon.mhm


1 Answers

You need to get the value of the src attribute, then request the URI with XMLHttpRequest … at which point you are better off not using a <script type="not-js"> at all.

Browsers don't automatically download unknown script types, and they don't make scripts accessible programatically to JS. You can access inline scripts as they are part of the DOM, external scripts are not.

like image 158
Quentin Avatar answered Oct 14 '22 08:10

Quentin