PHP Template Global Variables
[email protected] (David Wheeler) Fri, 21 Oct 2005 23:59:43 -0700
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
Hi All, Apologies for cross-posting, but I wanted to get feedback both from the Bricolage camp and from the PHP camp. Right now, the Bricolage PHP burner sets up a single global variable, $BRIC. In it, you can access the typical Bricolage templating objects: <?= $BRIC['story']->get_title() ?> However, in Mason and Template Toolkit templates, you can access these things directly: <% $story->get_title %> [% story.get_title %] Now, the reason these variables ($story, $element, and $burner) are stored in $BRIC is because, as George told me, sticking stuff into the PHP global namespace is considered bad manners. Well, it's also bad manners in Mason, but I'm starting to lean toward moving these variables directly into the PHP namespace for consistency with the Mason and TT burners, as well as for simpler code: <?= $story->get_title() ?> Since the Bricolage templates are a relatively controlled environment, I'm personally not too worried about the pollution. But what do you think? One wrinkle: code evaluated from the PERL_LOADER directive currently can export symbols into the namespace used by the Mason and TT templates. For example, if I have PERL_LOADER = use HTML::Entities; Then I can use the exported encode_entities() function directly in the Mason or TT templates: <% encode_entities($story->get_title) %> [% encode_entities(story.get_title) %] I'd like to do this in the PHP templates, too, but this also means that more stuff will be stuck into the global namespace: <?= encode_entities($BRIC['story']->get_title()) ?> So getting rid of $BRIC[] and just using $story, $element, and $burner directly goes right along with that: <?= encode_entities($story->get_title()) ?> Granted, HTML::Entities is not a great example (I know that PHP has its own functions for that), but there are other useful things exported by PERL_LOADER code, such as burner constants. So consider it a given that Bricolage will be putting PERL_LOADER exports into the PHP namespace. Anyway, your feedback would be greatly appreciated. Many TIA, David