Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 13 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow patTemplate arrow Customisation arrow Reading from any datasource

Reading from any datasource PDF Print E-mail

If you would like to store your templates anywhere else, you can simply create a new reader. Just create a new subclass of patTemplate_Reader and place it into the reader directory.

You need to implement at least one method: readTemplates(). patTemplate will call this method, whenever the user calls patTemplate::readtemplatesFromInput() and will pass the unique identifier for the template to read. This can be a filename, a URL or the value of a primary key in a database.

After reading the template, you will have to return an array, that contains the template structure. In most cases you will be able to use patTemplate_Reader::parseString(), which will apply regular expressions to split the template source into several blocks and interprets all tags.

01        <?PHP
02        /**
03        * patTemplate Reader that reads from a file
04        *
05        * @package       patTemplate
06        * @subpackage    Readers
07        * @author        Stephan Schmidt <>
08        */
09        class patTemplate_Reader_File extends patTemplate_Reader
10        {
11           /**
12            * reader name
13            * @access    private
14            * @var        string
15            */
16            var $_name ='File';
18           /**
19            * read templates from any input
20            *
21            * @final
22            * @access    public
23            * @param    string    file to parse
24            * @return    array    templates
25            */
26            function readTemplates( $input )
27            {
28                $this->_currentInput = $input;
29                $fullPath  = $this->_resolveFullPath( $input );
30                $content   = file_get_contents( $fullPath );
32                $templates = $this->parseString( $content );
34                return $templates;
35            }
37           /**
38            * resolve path for a template
39            *
40            * @access    private
41            * @param    string        filename
42            * @return    string        full path
43            */   
44            function _resolveFullPath( $filename )
45            {
46                $baseDir  = $this->_options['root'];
47                $fullPath = $baseDir . '/' . $filename;
48                return $fullPath;
49            }
50        }?>

If you want to support the parse="off" functionality for external templates, you will have to create a second method called loadTemplate(). This method will receive a unique identifier and should return the data associated with it as a string. In the above example, you would just strip the call to parseString().
Possible readers

    * Read from database
    * Read from a template server
    * Read from shared memory

Other template engines

Readers may also be used to read templates that have been created for other template enginges than patTemplate. We already delivered a reader, that is able to read templates that have been created for HTML_Template_IT and treat them like patTemplate templates.
If you want to implement a reader for other engines, you'll have to make yourself fimiliar with the internal structure of patTemplate. We'll post more information on this subject at a latter point.

patTemplate supports caching of the returned templates structures. As the caching is still in beta state and the internal plugin API may change, documentation on this topic will follow, once the API is stable enough.

Last Updated ( Friday, 31 December 2004 )
< Prev   Next >