Awesome
Pure PHP Template Engine
Demo
Quick Start
index.php
<?php
require_once 'phiz/View.class.php';
$dir = dirname(__FILE__);
PhizView::setTemplateDir($dir . '/template');
PhizView::setMapDir($dir . '/map');
//init page and display
PhizView::page('foo-bar:page/Index.class.php')->display();
PhizView
a widget or block
source code (php style):
<?php
//access permission
$this->scope('private');
//static resources
$this->import('lib/jquery/jquery.js');
$this->import('lib/bootstrap/bootstrap.css');
//inputs
$content = $this->input('content', 'hello world');
?>
<!-- html of view -->
<div><?php echo $content; ?></div>
source code (php class style)
<?php
class Foo_Widget_Bar extends PhizView
{
protected function init()
{
//access permission
$this->scope('private');
//static resources
$this->import('lib/jquery/jquery.js');
$this->import('lib/bootstrap/bootstrap.css');
}
protected function loadTemplate()
{
//inputs
$content = $this->input('content', 'hello world');
$html = '<!-- html of view -->';
$html .= "<div>{$content}</div>";
return $html;
}
}
API Documentation
PhizView
- input($key, $default = null): get inputs
- import($id): require static resources.
- load($id): load other view.
- scope($type): define access permission.
- css(): display required css resources.
- js(): display required js resources.
- startScript(): ob_start to collect script code.
- endScript(): ob_get_clean to stop collecting script code.
- script(): display collected script code.
- display(): echo rendered html
- fetch(): return rendered html
- getPageData($key, $default): get data from the unique PhizPage instance.
PhizPage extend PhizView
- buildPage(): abstract, return page rendered html.