Configuration methods

PHPTAL tries to use best defaults possible and you shouldn't need to change any of the settings.

All of these are methods of the PHPTAL class. set* methods return instance of their class, so you can chain them:

echo $phptal->setPhpCodeDestination('/tmp/phptal')->setOutputMode(PHPTAL::XML)->setTemplate('tpl.zpt')->execute();

is the same as:

echo $phptal->execute();

There are other set* methods for filters, internationalization, etc. They have been described in other sections of this manual.


Changes what syntax is used when generating elements. Valid modes are:


In this mode (which is default) PHPTAL will output XHTML in a way that is backwards-compatible with HTML browsers.

  • Empty elements will be forced to use self-closing form (<img/>, <link/>), and non-empty elements will always have closing tag.


    XHTML output mode changes <link> element in way that is incompatible with RSS. Use XML output mode to generate RSS feeds or use Atom.

  • Boolean attributes (checked, selected, etc.) will always have value required by the XHTML specification (it simplifies use of tal:attributes).

  • <![CDATA[ blocks will be added or removed automatically and will use special escaping syntax that is safe in both XML and HTML.


    If you're always sending XHTML as application/xhtml+xml, then it's better to use XML output mode.


This mode generates documents that have best compatibility with text/html parsing in current web browsers, but are not XML.

PHPTAL will change DOCTYPEs to <!DOCTYPE html>. Namespace declarations, name prefixes, explicit CDATA sections and other HTML-incompatible constructs will be omitted.


This mode is not a "tag soup". PHPTAL will close all elements properly and quote attributes when it's necessary. Output will be properly formatted HTML 5, and fully backwards-compatible with current HTML 4 browsers.


This mode outputs "pure" XML without compatibility with text/html parsing. Use this mode when generating feeds, SVG, MathML, RDF and other XML files.


Specify character encoding used by your templates. The default is UTF-8.

PHPTAL assumes that encoding of all templates and generated documents is the same. BOM (Byte Order Marker) is removed from UTF-8 documents.


PHPTAL does not read encoding from XML files and never converts character encodings.


Save yourself trouble and always use UTF-8 for everything.

Other methods


Specifies where to look for templates. If given a string, it adds it to the list of paths searched. If given array, it replaces the list.

This doesn't mean all your files need to be in the root directory, you can use sub folders to organize your template designer's work. It's just a shortcut which will allow you to reference templates without specifying the real path, but instead their relative path within the repository.


It's like include_path, but for PHPTAL templates only.


To tell PHPTAL where to store its intermediate (temporary) PHP files. By default it uses directory given by PHP's sys_get_tmp_dir(), which usually is '/tmp/' directory.


What filename extension should be used for intermediate PHP files. The default is php and frankly, there's no reason to change it.


Maximum number of days intermediate files and fragments cached with phptal:cache should be kept.

The default is 30 days. Cache is scanned and cleaned up only when PHPTAL recompiles a file, and only (on average) once per 30 recompiles. You can simply delete cached files if you don't want to wait until PHPTAL clears them.


Forces reparsing of all templates all the time. It should be used only for testing and debugging. It's useful if you're testing pre filters or changing code of PHPTAL itself.


This slows down PHPTAL very much. Never enable this on production servers!