Reputation: 203
In Django, lets say I want to import a javascript file using script src="blah.js"
I pass in a template variable {{ business }}. Is there a way for the static javascript file blah.js to access {{ business }}? I can do it with javascript in the html templates but once I call a static script it doesn't work. It seems like it'd be best to separate javascript files I call in multiple templates into a javascript file so I thought it might be possible.
Upvotes: 1
Views: 1138
Reputation: 9726
You redesign your code in such a way that in the templates you make calls to javascript functions with the template variables as arguments:
<script type="text/javascript">
x = foo({{ business }}, {{ some_other_variable }});
alert(x);
</script>
Upvotes: 2