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 ""
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With