Scripting help needed (pass variables to javascript in a UDT)
Posted: Wed Dec 06, 2006 10:24 pm
I want to take values entered into the Page edit, from hidden single line content areas in the template and pass them as parameters to a Javascript built into a UDT. I know generally how to do it using the ASSIGN freom smarty, IF the UDT was all in PHP, but not how to pass the variable to this GoogleMaps API (i.e. I want my user to enter the name, address, city/prov and postal code in four fields in their admin backend, then assemble them together to send to the GoogleMap API UDT to output a nice little location map.
Here's the code that I have input into its own Content block to hand code for each page now:
and I am assuming if I had an appropriate UDT, I would use something like this in the template:
If you can even pass more than one parameter to a UDT?? CAn anyone here help me with amending the UDT Javascript code for teh googleMap API function (above) so it can accept variables input in the backend Page fields?
Many thanks in advance.
Wayne
Here's the code that I have input into its own Content block to hand code for each page now:
Code: Select all
{literal}
<__script__ type="text/javascript">
//<![CDATA[
var geocoder;
var map;
var address = "345 Anywhere Street East, Smalltown, ON, M4Z 3Z6";
var name = "A Great Place to Be"
var url = 'http://maps.google.com/?q=' + name + address + '&z=16&t=m';
function load()
{
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
geocoder.getLocations(address, addToMap);
map.addControl(new GSmallMapControl()); }
}
function addToMap(response)
{
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
marker = new GMarker(point);
map.setCenter(point, 15);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function() {
window.open(url, "_blank","menubar=yes,scrollbars,resizable=yes,width=640,height=480");});
}
//]]>
</__script>
{/literal}
<div id="map"></div>
Code: Select all
<div id="hidden">{content block="name" assign=name oneline='true' wysiwyg='false'}</div>
<div id="hidden">{content block="address" assign=address oneline='true' wysiwyg='false'}</div>
<div id="hidden">{content block="city" assign=city oneline='true' wysiwyg='false'}</div>
<div id="hidden">{content block="postalcode" assign=postalcode oneline='true' wysiwyg='false'}</div>
{googleMap name="$name" address="$address" city="$city" postalcode="$postalcode"}
Many thanks in advance.
Wayne