You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by GZ Dark <gz...@hotmail.com> on 2006/10/07 17:12:21 UTC

what's the best way to share variables between main script and template files

Hello,list,

Give my main srcipt is index.cgi,it require the two files of "header" and 
"footer" which are HTML templates.
Where in index.cgi:

use "header";

some logic codes...

use 'footer";


Then it'll generate a dynamic page.

My question is,how can I share the variables defined in the index.cgi 
between index.cgi and the two templates?

For example,I have a var in the index.cgi:

our %hash = (...);

then in the template files,I can see it by:

our $hash;
<br>$hash{'key1'}</br>

But is it the best way to use global vars for the sharing under modperl?is 
there any other good way?Thanks.



Re: what's the best way to share variables between main script and template files

Posted by Jonathan <mo...@2xlp.com>.


On Oct 7, 2006, at 11:12 AM, GZ Dark wrote:

> But is it the best way to use global vars for the sharing under  
> modperl?is there any other good way?Thanks.

pnotes


personally though, i think you should opt for a more OOP approach and  
create a new header and footer object , explicitly passing in the  
variables you want.