PHP code example of xorock / zend-phptal

1. Go to this page and download the library: Download xorock/zend-phptal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xorock / zend-phptal example snippets



return [
    'zfphptal' => [
        'cache_dir' => 'path to cached templates',
        // if enabled, delete all template cache files before processing
        'cache_purge_mode' => boolean,
        // set how long compiled templates and phptal:cache files are kept; in days 
        'cache_lifetime' => 30,
        'encoding' => 'set input and ouput encoding; defaults to UTF-8',
        // one of the predefined constants: PHPTAL::HTML5,  PHPTAL::XML, PHPTAL::XHTML
        'output_mode' => PhptalEngine::HTML5,
        // set whitespace compression mode
        'compress_whitespace' => boolean,
        // strip all html comments
        'strip_comments' => boolean,
        // if enabled, forces to reparse templates every time
        'debug' => boolean,
    ],
];

<a tal:attributes="href php: this.url('sample_route')">link</a>

return [
    'view_helpers' => [
        'aliases' => [
            'test' => \My\View\Helper\Test::class,
        ],
        'factories' => [
            \My\View\Helper\Test::class => \Zend\ServiceManager\Factory\InvokableFactory::class
        ],
    ],
];


// inside template
// ${php: this.test()}

$this->engine->set('doctype', $this->plugin('Doctype'));
$this->engine->set('headTitle', $this->plugin('HeadTitle'));
$this->engine->set('headScript', $this->plugin('HeadScript'));
$this->engine->set('headLink', $this->plugin('HeadLink'));
$this->engine->set('headMeta', $this->plugin('HeadMeta'));
$this->engine->set('headStyle', $this->plugin('HeadStyle'));