Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

call tpl in javascript

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Mon Apr 07, 2014 10:32 pm    Post subject: call tpl in javascript Reply with quote

Hi,

not work function tpl in javascript, Can you help me?


Code:


{literal}

<style type="text/css">
 body { font: normal 10pt Helvetica, Arial; }
 #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
 </style>
 <script src="http://maps.google.com/maps/api/js?v=3&key=&sensor=true" type="text/javascript"></script>
 
 <script type="text/javascript">
 //Sample code written by August Li
 var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
 new google.maps.Size(32, 32), new google.maps.Point(0, 0),
 new google.maps.Point(16, 32));
 var center = null;
 var map = null;
 var currentPopup;
 var bounds = new google.maps.LatLngBounds();
 function addMarker(lat, lng, info) {
 var pt = new google.maps.LatLng(lat, lng);
 bounds.extend(pt);
 var marker = new google.maps.Marker({
 position: pt,
 icon: icon,
 map: map
 });
 var popup = new google.maps.InfoWindow({
 content: info,
 maxWidth: 300
 });
 google.maps.event.addListener(marker, "click", function() {
 if (currentPopup != null) {
 currentPopup.close();
 currentPopup = null;
 }
 popup.open(map, marker);
 currentPopup = popup;
 });
 google.maps.event.addListener(popup, "closeclick", function() {
 map.panTo(center);
 currentPopup = null;
 });
 }
 function initMap() {
 map = new google.maps.Map(document.getElementById("map"), {
 center: new google.maps.LatLng(0, 0),
 zoom: 14,
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 mapTypeControl: false,
 mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 });


 [b]{foreach from=$var_list item=i}
("addMarker({$i.x}, {$i.y},'<b>{$i.bizname}</b><br/>{$i.add1}');\n");
 
 {/foreach}[/b]

 center = bounds.getCenter();
 map.fitBounds(bounds);
 
 }
 </script>
{/literal}

 





Thanks
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Apr 08, 2014 1:25 pm    Post subject: Reply with quote

Code:
{foreach from=$var_list item=i}
("addMarker({$i.x}, {$i.y},'<b>{$i.bizname}</b><br/>{$i.add1}');\n");
 
 {/foreach}


Smarty tags will not be processed inside {literal} tags.
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Tue Apr 15, 2014 5:27 pm    Post subject: foreach in javascript not work Reply with quote

Hi,

thanks

Not work, why? i cam help-me?

Quote:
<script type="text/javascript" src = "http://maps.google.com/maps/api/js?sensor=false">
</script>
{literal}
<script type="text/javascript">
var locations = [
{/literal}

{foreach from=$var_list item=i}
{$i.bizname}
{/foreach}
{literal}
];

// Setup the different icons and shadows
var iconURLPrefix = 'images/';

var icons = [
iconURLPrefix + 'marker1.png',
iconURLPrefix + 'marker2.png',
iconURLPrefix + 'marker3.png',
iconURLPrefix + 'marker4.png',
iconURLPrefix + 'marker5.png',
iconURLPrefix + 'marker6.png',
iconURLPrefix + 'marker7.png'
]
var icons_length = icons.length;


var shadow = {
anchor: new google.maps.Point(5,13),
url: iconURLPrefix + 'msmarker.shadow.png'
};

var map = new google.maps.Map(document.getElementById('map'), {
zoom: -5,
center: new google.maps.LatLng(40.715618, -74.011133),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
disableDefaultUI: true,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});

var infowindow = new google.maps.InfoWindow({
maxWidth: 400,
maxHeight: 350
});

var marker;
var markers = new Array();

var iconCounter = 0;

// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2], locations[i][3], locations[i][4], locations[i][5], locations[i][6], locations[i][7]),
map: map,
icon : icons[iconCounter],
shadow: shadow
});

markers.push(marker);

google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));

iconCounter++;
// We only have a limited number of possible icon colors, so we may have to restart the counter
if(iconCounter >= icons_length){
iconCounter = 0;
}
}

function AutoCenter() {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
$.each(markers, function (index, marker) {
bounds.extend(marker.position);
});
// Fit these bounds to the map
map.fitBounds(bounds);
}
AutoCenter();
</script>
</div>
<script type="text/javascript" src="maps/js/jquery-1.7.1.min.js"></script>


{/literal}


thanks again
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Apr 15, 2014 9:39 pm    Post subject: Reply with quote

What does the output look like? Does it look like you want? Any php error logs? You have to do some debugging.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP