echoExecute() method

Since most common use of execute() method is to echo its output, PHPTAL offers convenience method that echoes output immediately without buffering. This enables streaming of arbitrarily large output without hitting memory limit.

Note

Fragments of template that use tal:on-error or phptal:cache are buffered regardless.

The code:

<?php
    $tpl = new PHPTAL('template.xhtml');
    $tpl->echoExecute();
?>

is same as:

<?php
    $tpl = new PHPTAL('template.xhtml');
    echo $tpl->execute();
?>

but little faster.

Warning

Currently echoExecute() method has some unexpected limitations.

Limitations

When echoExecute() is used, PHPTAL will throw exception if you call any macro defined in a file that has XML declaration or DOCTYPE.

Typically PHPTAL allows templates to "inherit" DOCTYPE from another file (useful when subpage is calling main layout template), however that is not possible without buffering.

To work around this you can:

  • Keep using echo $tpl->execute() until this limitation is lifted.

  • Remove all DOCTYPEs and XML declarations from templates and echo them from PHP before calling echoExecute().