PHP Integration


Table of Contents

1. Defines
2. class PHPTAL
3. interface PHPTAL_Filter
4. interface PHPTAL_Trigger
5. interface PHPTAL_TranslationService
5.1. method setLanguage(...)
5.2. method useDomain($domain)
5.3. method setVar($key,$value)
5.4. method translate($key)
6. Working with gettext
6.1. Creating the translation directory structure
6.2. Portable Object files
6.3. Translation Domain
6.4. PHP usage in PHPTAL
6.5. Variable interpolation
7. Creating custom expression modifiers

This section is aimed at PHP developers and explains how to use and customize PHPTAL behaviours for simple and advanced usage.

1. Defines

After the inclusion of PHPTAL library, some defines will be created in PHP context, all these defines come from PHPTAL.php file:

  • PHPTAL_VERSION: version of PHPTAL library installed on your system (in format: X.X.X)

  • PHPTAL_PHP_CODE_DESTINATION: this is the path where intermediate PHP files produced by PHPTAL will be stored. This define may be overwritten before the inclusion of PHPTAL.php, the specified path must contain the leading path separator.

You can configure some PHPTAL features by defining some constants:

To tell PHPTAL to ignore intermediate php files and to reparse templates every time:

<?php
define('PHPTAL_FORCE_REPARSE', 1);
require_once 'PHPTAL.php';
?>

To tell PHPTAL to store its intermediate PHP files other than in the '/tmp/' directory:

<?php
define('PHPTAL_PHP_CODE_DESTINATION', '/path/to/somewhere/');
require_once 'PHPTAL.php';
?>

If all your files are stored in a base directory (repository), you can define PHPTAL_TEMPLATE_REPOSITORY as follows:

<?php
define('PHPTAL_TEMPLATE_REPOSITORY', '/path/to/templates/root');
require_once 'PHPTAL.php';
?>

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.