I am trying to use smarty variables inside javascript inside tpl
{literal}
<script language="javascript">
google.load('visualization','1',{'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
data.addRows(4);
data.addColumn('string', 'Location');
data.addColumn('number', 'Number of links');
{/literal}{foreach from=$last5 item=link name=links key=index}
data.setValue({$index},0,'{$link.location|replace:'\'':'\\\''}');
data.setValue({$index},1,{$link.location_count});
{/foreach}{literal}
var options = {};
options['dataMode'] = 'regions';
options['region'] = 'world';
var container = document.getElementById('map');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
{/literal}
can you suggest me a solution please
Simply close the {literal} tag right before inserting the smarty variable, and re-open it again.
Or use {ldelim} and {rdelim} for the pieces of code where you assign values from Smarty.
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