[Chameleon] Mixing PHP & Chameleon Widgets?

Paul Spencer pspencer at dmsolutions.ca
Sun May 29 21:44:38 EDT 2005


You can load templates from a URL instead of a file, I believe that 
works 'out of the box' with the service instance (cwc2) but would need 
some additional code in the regular mode of operation.

One client did this to load language-specific templates ... they 
requested the template through a jsp page and passed a language value 
and returned the appropriately translated template.  Which was a slick 
way around how chameleon currently requires multiple templates to 
support multiple languages.

If you did this, you could then embed whatever you wanted in the 
template, as long as the script returned HTML and CWC2 tags.

I don't think we will ever entertain allowing code in templates, the 
security concerns override any potential benefit IMHO.

Cheers

Paul

Liz Godwin wrote:
> Hi BIll,
>  
> I was going to reply straight off the bat and suggest that this cannot 
> be done, because at one point, early in my Chameleon experience, I 
> wanted to this...  BUT  I had a thought...
>  
> I believe it IS possible to read in a template from a URL.  Might be 
> risky ... but I think it's possible.  If you read in a template in this 
> way it is processed by the web server before passed along, which means 
> PHP gets in there.  You'd have to read in the template and save it as 
> a file though I think.  I have an example where I did this with a remote 
> context document, but I havn't tried with remote templates.  I'd like my 
> templates to be predictable.
>  
> There also might be path issues I havn't thought of yet...
>  
> All of this pointing and saving of a remote file would happen in the 
> index.phtml file that calls chameleon.
>  
> Sample:
> //$szURL is a url of a context document in this case
> if (isset($szURL)) {
>  $aszFile = file( $szURL );
>  $szContext = tempnam($_SESSION['gszTmpPath'], "context").".cml";
>  $fh = fopen($szContext, "w");
>  $nLines = count($aszFile);
>  for($i=0; $i<$nLines; $i++) {
>    fwrite($fh, $aszFile[$i]);
>  }
>  fclose($fh);
> }
>  
> $oApp->moMapSession->oMap->loadMapContext( $szContext );
>  
> Depending on what you want to build dynamically into your 
> template...building a simple widget is actually not as bad as it might 
> seem....
> 
> Cheers,
> Liz Godwin
> 
> PS.  Sorry if you get this twice Bill, I forgot to reply to the list as 
> well.
>  
> On 5/19/05, *Bill Binko* <bill at binko.net <mailto:bill at binko.net>> wrote:
> 
>     Ok, I'm going to show my cluelessness here for a minute.
> 
>     I'm looking to integrate map elements into pages that already
>     include PHP
>     code.
> 
>     I understand the goal of separating the markup and the logic, but I
>     would
>     like to embed widgets in pages that are dynamically created, and the
>     systems they work with don't have a Tag-based abstraction layer.
> 
>     Is there a way to do this?  Is there a way to setup Chameleon so that
>     after it has done it's processing it feeds the results back into PHP to
>     execute?  Or perhaps the opposite (PHP first, then Chameleon)?  I
>     think I
>     can manage with either of those solutions.
> 
>     If not, I will have to encapsulate all of that existing logic into
>     Chameleon widgets (and I'm not sure I can consolidate it as well as I'd
>     need to.  That is, I'd have many widgets that had to cooperate.
> 
>     Any pointers for a newbie would be appreciated.
> 
>     Bill
>     _______________________________________________
>     Chameleon mailing list
>     Chameleon at lists.maptools.org <mailto:Chameleon at lists.maptools.org>
>     http://lists.maptools.org/mailman/listinfo/chameleon
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon

-- 
+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+


More information about the Chameleon mailing list