I have a map generated in JS.
I need to set the country-id
and url
for each country. Both 'country-idand
urlare fields in my Craft categories group
countries`.
{
"country-id": "FR",
"url": "http://mysite/country/france"
},
I know (basically) how to output to JS for use in my templates. Here is a link to an earlier question I asked on how to output to JS. This time my question is not how to include JS, but how do I generate a specific output.
How do I incorporate a for loop
that produces the desired output for each member of the category country
.
{% set nations = craft.categories.group('country') %}
{for country in nations %}
{
"country-id": "{{country.CountryCode}}",
"url": "{{country.url}}",
},
{% endfor %}
Part of the problem is how to I get the loop to also output the script brackets, quotes, commas and attributes that surround the data for each country?
UPDATE -- MORE INFO --- This is the full JS that the above is taken.
<script type="text/javascript">
var map = AmCharts.makeChart( "chartdiv", {
"type": "map",
"theme": "light",
"dataProvider": {
"map": "worldLow",
"areas": [
{
"id": "FR",
"url": "http://fmysite.dev/country/france"
},
{
"id": "JP",
"url": "http://mysite.dev/country/japan"
},
{
"id": "SA",
"url": "http://mysite.dev/country/saudi-arabia"
},
{
"id": "GB",
"url": "http://mysite.dev/country/united-kingdom"
},
]
},
"smallMap":{},
"areasSettings": {
// color of areas listed
"color": "#71d1d7",
// color of area's outline
"outlineColor": "#4e93aa",
// Color of area's outline when user rolls-over it.
"rollOverOutlineColor": "#000",
// Color of all areas which are in the map svg file, but not listed as areas in DataSet
"unlistedAreasColor": "#c7ecf4",
// Color of all areas' outline which are in the map svg file, but not listed as areas in DataSet
"unlistedAreasOutlineColor": "#c7ecf4"
},
"listeners": [ {
"event": "clickMapObject",
"method": function( e ) {
// check if clicked map object contains "ajaxUrl" parameter
if ( e.mapObject.ajaxUrl !== undefined ) {
// add "description" if it was empty
if ( e.mapObject.description === undefined )
e.mapObject.description = "<div id='mapcontent'>Loading...</div>";
// delay loading by a bit so that map can finish displaying description box and zoom
setTimeout( function() {
$( "#mapcontent" ).load( e.mapObject.ajaxUrl );
}, 1000 );
}
}
} ]
} );
</script>