[Chameleon] Resizeable Map - my next prob

Paul Spencer pspencer at dmsolutions.ca
Tue Mar 15 07:40:48 EST 2005


Peter,

you cannot include php code in the template by design.  This may seem 
like an unnecessary limitation, but it is actually required for security 
reasons since there is a mode for Chameleon to allow uploading of 
templates from remote sites.  Allowing php in the template would allow 
execution of arbitrary code by unknown third parties, which would be bad :)

You can accomplish the same thing, however, using the template 
pre-processor:

in index.phtml:

//$aApp->setVar _MUST_ come after $oApp->CWCInitialize();
$oApp->CWCInitialize();

$size = "640x480";
$size_array = explode("x",$size);
$size_width = $size_array[0];
$size_height = $size_array[1];

$oApp->setVar( 'size_width', $size_width );
$oApp->setVar( 'size_height', $size_height );

and then in your template file,

<CWC2 TYPE="MapDHTML"
WIDTH="[$size_width|640$]"
HEIGHT="[$size_height|480$]"
VISIBLE="true"
ALLOWRESIZE="true"
MARQUEECOLOR="#FF3333"
MARQUEEWIDTH="2"
MINSCALE="1"
/>

The value after the | is the default value if the name before the | is 
not set

The names that are available to the template pre-processor are anything 
coming from a previous page's $_REQUEST (get and post form variables and 
query string) plus anything added programmatically using $oApp->setVar()


Note that for map size, the MapDHTML widget already includes hidden form 
variables for controlling the map size which you can modify directly to 
cause the map size to change (which is what the MapSize widget does). 
For instance, you can use a javascript function like this to change the 
map size:

function myChangeMapSize( width, height )
{
     document.forms[0].MAP_WIDTH.value = width;
     document.forms[0].MAP_HEIGHT.value = height;
     document.forms[0].submit();
}

Cheers

Paul

Peter Thomann wrote:
> I tried to parse a variable to the template file that defines the width and
> height of my displayed map. this doesn't work isn't it possible to include
> php code in the template file?
> is there another way to solve this problem any solutions are welcome
> i only need a few sizes or is it even possible to have a easy - like window
> resize - function.
> <td align="center">
> 	<?php
> 		$size = "640x480";
> 		$size_array = explode("x",$size);
> 		$size_width = $size_array[0];
> 		$size_height = $size_array[1];
> 	?>
> 	<CWC2 TYPE="MapDHTML"
> 		VISIBLE="true"
> 		<?php
> 			echo "WIDTH=\"$size_width\"\n";
> 			echo "HEIGHT=\"$size_height\"\n";
> 		?>
> 		ALLOWRESIZE="true"
> 		MARQUEECOLOR="#FF3333"
> 		MARQUEEWIDTH="2"
> 		MINSCALE="1"
> 	/>
> </td>
> 


More information about the Chameleon mailing list