This question has been asked in multiple ways, however the solutions such as defining variables before the script tag haven't worked.
template.html
<script>
var locations = {{ some_variable }}
</script>
<script type="text/javascript" src="{% static 'base/scripts/maps.js' %}"></script>
I believe this is because maps.js
is actually a function. The start of it is as follows:
maps.js
(function($){
"use strict";
function mainMap() {
var ib = new InfoBox();
// Infobox Output
function locationData(locationURL,locationImg,locationTitle, locationAddress, locationRating, locationRatingCounter) {
return('SOME_HTML_WITH_VARIABLES')
}
// Locations
var locations = [
[ locationData('listings-single-page.html','images/listing-item-01.jpg',"Tom's Restaurant",'964 School Street, New York', '3.5', '12'), 40.94401669296697, -74.16938781738281, 1, '<i class="im im-icon-Chef-Hat"></i>'],
];
What I want to do is to pass location data from my model e.g.
{% for model in query_list %}
[ locationData('link_to','img_url','{{ model.name }}','{{ model.address }}', '5', '10'), {{ model.latitude }}, {{ model.longitude }}, {{ forloop.counter }}, '{{ model.icon }}'],
{% endfor %}
Possible solution:
Post the whole maps.js
file in the template.html, inside the script tag. But this file has 10000+ lines.