[development] theme_foo() functions vs tpl.php templates (was Move all core modules into their own directories)

Adrian Rossouw adrian at bryght.com
Thu May 4 13:27:23 UTC 2006


On 04 May 2006, at 3:10 PM, Jonathan Chaffer wrote:
> Your module:
>   function theme_foo($bar) {
>       $variables = array(
>         'bar' => $bar,
>       );
>       return _phptemplate_callback('foo', $variables);
>   }
Actually :  The 'phptemplate' part of it is not necessarily true.

With META INFORMATION the theme engine doesn't have to have a  
_templates() hook,
which means it can just tell system_listing what extension to search  
for to find templates. (ie: *.tpl.php, or *.tal).
This was one of the first places I wanted to introduce meta- 
information but later removed it at Dries' request.

Every single contrib theme engine (except perhaps xtemplate) is a  
copy paste job from phptemplate, re-implementing perhaps
a max of 2 functions.

Originally I had 3 namespaces.

1 : theme_ : what drupal ships with.
2 : engine_ : ie what phptemplate_node and phptemplate_page should  
have been (engine_node, engine_page)
3 : template_ : instead of having $themename_ functions, all of them  
were centralised under template_

This all works, because in my design you should never have multiple  
theme engines, or multiple themes loaded at the same time.

I built the theme engine system initially to have this level of  
abstraction in core, but when it wasn't accepted, i moved it
into phptemplate.

'phptemplate' it self is just this code :

function _phptemplate_render($file, $variables) {
   extract($variables, EXTR_SKIP);  // Extract the variables to a  
local namespace
   ob_start();                      // Start output buffering
   include "./$file";               // Include the file
   $contents = ob_get_contents();   // Get the contents of the buffer
   ob_end_clean();                  // End buffering and discard
   return $contents;                // Return the contents
}

The useful part of phptemplate is the variable collection and  
filtering semantics.

If all the rest of phptemplate is moved into core as engine_  
functions, and we nothing else.
most other template engines can be implemented by just creating  
_phptal_render($file, $variables)
or whatever.



--
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com




More information about the development mailing list