//composer.json { "require": { "phpixie/template": "3.*@dev", "phpixie/slice": "3.*@dev", "mthaml/mthaml": "1.7.0" } }
<?php class HamlFormat implements \PHPixie\Template\Formats\Format { protected $mtHaml; public function __construct() { $this->mtHaml = new \MtHaml\Environment('php'); } // public function handledExtensions() { return array('haml'); } // public function compile($file) { $contents = file_get_contents($file); return $this->mtHaml->compileString($contents, $file); } }
// // , $slice = new \PHPixie\Slice(); $config = $slice->arrayData(array( 'resolver' => array( 'locator' => array( // 'directory' => __DIR__.'/templates/', 'defaultExtension' => 'haml', ) ), 'compiler' => array( // 'cacheDirectory' => > __DIR__.'/cache/', ) )); $template = new \PHPixie\Template($slice, $config, array(), array( new HamlCompiler() ));
// layout.php <html> <title> <?php $this->block('title'); ?> </title> <body> <?php $this->childContent(); ?> </body> </html>
// fairy.php <?php $this->layout('layout'); ?> <?php $this->startBlock('title'); ?> Fairy page <?php $this->endBlock(); ?> <h2>Hello <?php $_($name); ?></h2>
include $this->resolve('fairy');
<?php $config = $slice->arrayData([ 'resolver' => [ 'locator' => [ 'type' => 'prefix', 'locators' => [ 'Site' => [ 'directory' => __DIR__.'/site/', ], 'Theme' => [ 'type' => 'group', 'locators' => [ [ 'directory' => __DIR__.'/templates/', ], [ 'directory' => __DIR__.'/fallback/', ], ] ] ] ] ] ]);
class HTML implements \PHPixie\Template\Extensions\Extension { public function name() { return 'html'; } // \ public function methods() { return array('escape', 'output'); } // // $_($name) $this->output($name) public function aliases() { return array( '_' => 'output' ); } // public function escape($string) { return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); } public function output($string) { echo $this->escape($string); } }
git clone https://github.com/phpixie/template cd template/examples # curl -sS https://getcomposer.org/installer | php php composer.phar install php quickstart.php
Source: https://habr.com/ru/post/253973/
All Articles