https://github.com/thinkphp/php-template-engine
PHP lightweight Template Engine with same interface as Savant3 and Smarty.
https://github.com/thinkphp/php-template-engine
Last synced: 23 days ago
JSON representation
PHP lightweight Template Engine with same interface as Savant3 and Smarty.
- Host: GitHub
- URL: https://github.com/thinkphp/php-template-engine
- Owner: thinkphp
- Created: 2011-02-21T11:44:33.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2011-02-21T12:23:38.000Z (about 15 years ago)
- Last Synced: 2025-12-09T00:23:49.427Z (4 months ago)
- Language: PHP
- Homepage: http://thinkphp.ro/apps/php-hacks/php-template-engine/demos/demo4Twitter2/go.php
- Size: 104 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP Template Engine
===================
Very simple template engine for PHP5 with same interface as Savant3 and Smarty. Assign content to engine, then display a template file.
How to use
----------
//path/to/templates
$path = 'templates/';
//create an object
$tpl = new Template($path);
//assign some content
$tpl->assign('title','PHP Template Engine');
//display the template
$tpl->display('header.tpl.php');
//create an object Template
$body = new Template($path);
//create an object Template
$a = new Template($path);
//assign some content
//this would typically came froma database or other source,
//but we'll use static value for the purpose of this example
$a->assign('result', $result);
$body->assign('label','Username: ');
//assign from
$body->assign('tweets', $a->fetch('content.tweets.tpl.php'));
//also, create an object Template
$footer = new Template($path);
//assigb static value
$footer->assign('written','thinkphp');
$footer->assign('download','#');
//assign values from another fetching template.
$body->assign('footer',$footer->fetch('footer.tpl.php'));
//display the template
$body->display('body.tpl.php');
It can be used with the following templates:
/* do something CSS */
if($result && is_array($result)) {
$out = '
';
$header = '-
'.
'@'.$result[0]['user']['screen_name'].''.
''.$result[0]['user']['location'].''.
''.
''.$result[0]['user']['description'].''.
' ';
$out .= $header;
foreach($result as $r) {
$out .= '
- ';
$out .= '';
$out .= '';
$out .= '';
$out .= ($r['text']);
$out .= '';
$out .= '';
$out .= '';
$out .= '
';
}
$out .= '
';
} else {
$out = 'No found results.';
}
//output the result
echo$out;
Written by @ | download on GitHub