Scripting help needed (pass variables to javascript in a UDT)

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
websherpa

Scripting help needed (pass variables to javascript in a UDT)

Post by websherpa »

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:

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>

and I am assuming if I had an appropriate UDT,  I would use something like this in the template:

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"}

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
websherpa

Re: Scripting help needed (pass variables to javascript in a UDT)

Post by websherpa »

Thank  you (tried that without success), but it's not what I really want to do.  I have the API working, it's just that I want to move it from the main code of my Page into a UDT and pass it variables from hidden input fields on the Page.  Sorry if I knew more coding, I might have the answer, but I'm looking for a coding example of how to pass a field variable to a javascript in a UDT.

Given this code in a page:

Code: Select all


<div id="hidden">{content block="name" assign=name oneline='true' wysiwyg='false'}</div>

What would be in the UDT to accept and dig out the passed variable "name" for JAvaScript?

Thanks in advance.
Locked

Return to “CMSMS Core”