humming/template

Fast Widget Template Without If Else

v0.0.3 2019-03-12 03:06 UTC

This package is not auto-updated.

Last update: 2024-05-15 05:09:52 UTC


README

This library provides a fast implementation of simple widgets.

Install

To install with composer:

composer require humming/template

Requires PHP 5.3 or newer.

Usage

Here's a basic usage example:

<?php

require '/path/to/vendor/autoload.php';

$templateDir = __DIR__ . '/template';
$compiledDir = __DIR__ . '/compiled';
$cache = new Psr\SimpleCache\CacheInterface();
$container = new Psr\Container\ContainerInterface();
$template = new \Humming\Template($templateDir, $compiledDir, new \Humming\Thigh($cache, $container), new \Humming\Pagination());

$template->assign('something', $somthing);
$template->display("test");
test.html
<html>
<body>
<h1>{$global.something}</h1>
</body>
</html>

Widgets

class HighSchoolStudent extends \Humming\Widget
{
    public function getItems($limit = 10, $name = '')
    {
        return array('title' => 'Students', 'rows=> array(
            array('id' => 1, 'name'=>'Li'),
            array('id' => 2, 'name'=>'Ming'),
            array('id' => 3, 'name'=>$name),
        );
    }
}
In Template
<html>
<body>
<h1>{var from=$widget.high_school_student.items.title name='Coco' limit=2 cache=3600}</h1>
<ul>
{section loop=$widget.high_school_student.items.rows limit=2 name='Coco'}
<li>{$rows.name}</li>
{/section}
</ul>
<h3>First Boy is {$widget.high_school_student.items.rows.0.name}</h3>
</body>
</html>

Include

<div class="main">{include file='main.html'}</div>

Paging

<div class="pagination">
{paging link="/test/?page=@number@" page=$global.page size=20 total=$global.total}
</div>

OR

<?php
$template->getPagination()->setUrl("/test/?page=@number@");
$template->getPagination()->setNumber(1);
$template->getPagination()->setSize(20);
$template->getPagination()->setTotal(100);
?>
<div class="pagination">
{paging template="/frontend/paging.html"}
</div>