[Chameleon] How to pass variable from app.php file to template.html?

Jason Fournier jfournier at dmsolutions.ca
Tue Jun 28 23:15:19 EDT 2005


Rhys,

You can do the following:

     $oApp->setVar( 'VARIABLE', 'VALUE' );

so, for instance:

     $oApp->setVar ('MYVAR', date('r') );

then in your template you can:

     [$MYVAR|default$]

In this instance, if MYVAR isn't set then default will be displayed.  You can easily omit the default value and nothing will be substituted ( ie, [$MYVAR$] ).

Note that you set this after you've initialized ($oApp->CWCInitialize()) the App and before you've executed ($oApp->CWCExecute())it.

Best Regards,
Jason



Rhys Ickeringill wrote:
> Hi All,
> 
> I'm trying to establish how one passes a variable from a chameleon php file
> to a chameleon template.
> 
> I see [#foo.html#] allows importing of external files into the template and
> [$bar$] get's substituted as by the value of $_REQUEST['bar'] during
> parsing. Is there a way to get the value of $foo (in code below) to be
> substituted into the parsed template? I'm guessing that I'll have to declare
> $foo global, but then what?
> 
> 
> <?php
>     include( "/absolute/or/relative/path/to/chameleon.php" );
> 
>     $szTemplate = "./sample_basic.html";
>     $szMapFile = "../map/chameleon.map";
> 
>     class SampleApp extends Chameleon{
>         function SampleApp(){
>             parent::Chameleon();
>             $this->moMapSession = new MapSession_RW;
>             $this->moMapSession->setTempDir( getSessionSavePath());
>             }
>         }
> 
>     $foo = 'bar';
> 
>     $oApp =  new SampleApp();
>     $oApp->registerSkin( 'skins/sample' );
>     $oApp->CWCInitialize( $szTemplate, $szMapFile  );
>     $oApp->CWCExecute();
> ?>
> 
> Thanks
> 
> Rhys
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon
> 

-- 
________________________
Jason Fournier

DM Solutions Group Inc.
jfournier at dmsolutions.ca
www.dmsolutions.ca
613.565.5056 x18



More information about the Chameleon mailing list