PHPlater, a simple template engine.

Related tags

Templating PHPlater
Overview

PHPlater

A simple PHP template engine that lets PHP do all the logic and then append it to the HTML in the template file. It is set to solve the problem of mixing too much logic into the template file itself and by that loosing some control over where the logic happens. You also get a bit more control over the data that is passed down to the template, and the code is easier to manage and to track.



Installation

PHP 8.0 or higher is needed for this class to work.

Use the package manager composer to install PHPlater.

composer install phplater/phplater

Simple Usage

Given this PHP code

$phplater = new PHPlater();
$phplater->plate('hello', 'world!');
echo $phplater->render('Hello {{hello}}');

This will be the output:

Hello world!

Advanced Usage

Some more examples are available under /examples and /tests

Given this template.tpl file

<div>
    One: {{ one }}<br />
    Two: {{ two.getTwo }}<br />
    Three: {{ assoc.three }}<br />
    Four: {{ assoc.4 }}<br />
    Five: {{ assoc.5.0 }}<br />
    Six: {{ assoc.six.0 }}<br />
    Seven: {{ seven_obj.returnArray.seven }}
</div>

And this PHP code

class Test {
    function getTwo() {
        return 'Kaksi';
    }
    public function returnArray() {
        return ['seven' => 'Seitsemän'];
    }
}

$phplater = new PHPlater();
$phplater->plates([
    'one' => 'Yksi',
    'two' => new Test(),
    'assoc' => [
        'three' => 'Kolme',
        4 => 'Neljä',
        5 => ['Viisi'],
        'six' => ['Kuusi']
    ],
    'seven_obj' => new Test()
]);

echo $phplater->render('template.tpl');

This will be the output:

<div>
    One: Yksi<br />
    Two: Kaksi<br />
    Three: Kolme<br />
    Four: Neljä<br />
    Five: Viisi<br />
    Six: Kuusi<br />
    Seven: Seitsemän 
</div>

Test

Run the following

vendor\bin\phpunit tests/PHPlaterTest.php

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Documentation

PHPDocumentator v.3.0 is used for generating documentation from PHPDoc in code. Download phpDocumentor.phar and run the following in the project folder to update it.

php c:/path/to/phpDocumentor.phar -d src -t docs

License

MIT

You might also like...
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine

This is an experiment for building ActiveRecord functionality on top of Doctrine2 using the Twig templating engine. Whether it is called Propel2 or not is irrelevant.

Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

A lightweight template parser used by PyroCMS.

Lex Lex is a lightweight template parser. Lex is released under the MIT License and is Copyrighted 2011 - 2014 PyroCMS Team. Change Log 2.3.2 Convert

A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

The Templating component provides all the tools needed to build any kind of template system.

Templating Component The Templating component provides all the tools needed to build any kind of template system. It provides an infrastructure to loa

Releases(v1.1.1)
Owner
John Larsen
John Larsen
⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

PHPPkg 19 Dec 9, 2022
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2.1k Jan 1, 2023
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 898 Dec 25, 2022
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 143 Dec 13, 2022
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 167 Dec 3, 2022
Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Vinicius 4 Oct 7, 2022
Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Harald Hanek 230 Aug 18, 2022
Pug (Jade) template engine for Symfony

Pug-Symfony Pug template engine for Symfony This is the documentation for the ongoing version 3.0. Click here to load the documentation for 2.8 Instal

Pug PHP 41 Dec 16, 2022
A template abstraction prototype for PHP template engines

Schranz Templating A template abstraction prototype for PHP template engines. This project should help to find a way for a general Template Render Int

Schranz Templating 16 Dec 7, 2022
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021