Prev |  | Next

### 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:

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

is the same as:

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

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

#### `setOutputMode( `mode`)`

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

`PHPTAL::XHTML`

  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.

    #### Warning

    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.

    #### Tip

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

`PHPTAL::HTML5`

  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.

  #### Note

  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.

`PHPTAL::XML`

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

#### `setEncoding( `encoding`)`

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.

#### Note

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

#### Tip

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

#### Other methods

##### `setTemplateRepository( `string_or_array`)`

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.

#### Tip

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

##### `setPhpCodeDestination( `path`)`

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.

##### `setPhpCodeExtension( `string`)`

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

##### `setCacheLifetime( `num_days`)`

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.

##### `setForceReparse( `boolean`)`

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.

#### Warning

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

Prev | Up | Next
class `PHPTAL` | Home | `execute()` method