Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n2ref/micro_templater
Simple and strong templater
https://github.com/n2ref/micro_templater
php template-engine
Last synced: 7 days ago
JSON representation
Simple and strong templater
- Host: GitHub
- URL: https://github.com/n2ref/micro_templater
- Owner: n2ref
- License: gpl-2.0
- Created: 2014-11-02T19:20:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-17T10:48:55.000Z (about 9 years ago)
- Last Synced: 2023-09-29T14:18:54.372Z (about 1 year ago)
- Topics: php, template-engine
- Language: PHP
- Size: 188 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Micro Templater
===============Simple but powerful PHP template engine.
Just one file.
Have a look how it easy to use.#### Examples
##### Variables
###### Example # 1 Using the method 'assign'```php
$html = '
Title
-
[var2]
';
$tpl = new Mtpl();
$tpl->setTemplate($html);
$tpl->assign('var1', 'foo');
$tpl->assign('[var2]', 'bar');
echo $tpl->render();
```
Result will look like:
```html
Title
-
bar
```
##### Blocks
###### Example # 1 A clear indication of the block
```php
$html = '
Title
';
$tpl = new Mtpl();
$tpl->setTemplate($html);
$tpl->touchBlock('error');
echo $tpl->render();
```
Result will look like:
```html
Title
```
###### Example # 2 Implicit indication block
```php
$html = '
Title
';
$tpl = new Mtpl();
$tpl->setTemplate($html);
$tpl->error->assign('[message]', 'Exemple 2: error message!');
echo $tpl->render();
```
Result will look like:
```html
Title
```
##### Loops
###### Example # 1 A list of menu
```php
$html = '
Title
';
$menu = array(
'home' => 'Home',
'gallery' => 'Gallery',
'help' => 'Help'
);
$tpl = new Mtpl();
$tpl->setTemplate($html);
foreach ($menu as $page_name => $title) {
$tpl->menu->assign('[URL]', '?view=' . $page_name);
$tpl->menu->assign('[TITLE]', $title);
$tpl->menu->reassign();
}
echo $tpl->render();
```
Result will look like:
```html
Title
```
##### Fill drop down
###### Example # 1
```php
$html = '
Title
Year
Submit
';
$tpl = new Mtpl();
$tpl->setTemplate($html);
$years = array(
2000 => '2000',
2005 => '2005',
2010 => '2010',
2015 => '2015'
);
$tpl->fillDropDown('year', $years, 2015);
echo $tpl->render();
```
Result will look like:
```html
Title
Year
2000
2005
2010
2015
Submit
```