An open API service indexing awesome lists of open source software.

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.

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 = '

  1. '.
    '
    @'.$result[0]['user']['screen_name'].'
    '.
    '
    '.$result[0]['user']['location'].'
    '.
    ''.
    '
    '.$result[0]['user']['description'].'
    '.
    '
  2. ';

    $out .= $header;
    foreach($result as $r) {
    $out .= '

  3. ';
    $out .= '';
    $out .= '';
    $out .= '';
    $out .= ($r['text']);
    $out .= '
    ';
    $out .= '
    ';
    $out .= '';
    $out .= '

  4. ';
    }
    $out .= '
';

} else {
$out = 'No found results.';
}
//output the result
echo$out;


Twitter







Written by @ | download on GitHub