I looked in the forum and found a topic on this, but the topic was over 6 months old and shown as locked.
I have included an OpenStreet map in a website and looked at using Leaflet JS to add the locations etc. As there are over 25 locations and some may need to be added etc I though I would be able to use CGBlog with custom fields to create the information and then pass the data as a variable to the JS script.
My knowledge is limited but I set up a summary template to just output the custom fields with the longitude and latitude information.
Code: Select all
{foreach from=$items item=entry name=maps}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
{if $field->name == "location"}
{capture name=siteloc assign=siteloc}{$field->value}{/capture}
{/if}
{/foreach}
{/if}
L.marker([{$siteloc}]).bindPopup("Some text").addTo(cities),
{/foreach}
Code: Select all
{capture name=mapviewx assign=mapview}{strip}{CGBlog summarytemplate=mapcs}{/strip}Variable{/capture}
then
{$mapview}
If I text the variable passing with straight text ie
Code: Select all
{content block="maptest" label="Map Test" wysiwyg="false" oneline="true" size="100" assign="maptest"}
Code: Select all
{assign var="mapt" value=$maptest}
{literal}
<__script__>
var cities = L.layerGroup();
var maptest = '{/literal}{$mapt}{literal}';
L.marker([55.8278, -4.0496]).bindPopup(maptest).addTo(cities);
However, when I switch to using CGBlog there's an error and the map disappears.
If I have a very simple template that renders just text ie
Code: Select all
{foreach from=$items item=entry name=maps}
Test Text
{/foreach}
Code: Select all
{foreach from=$items item=entry name=maps}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
{if $field->name == "location"}
{$field->value}
{/if}
{/foreach}
{/if}
{/foreach}
I haven't got as far as how to use the catured variable in the script as the script fails as soon as I try to assign the smarty variable to a js variable.
Sorry if this seems a bit convoluted but any suggestions would be greatfuly received.