PHPackages                             earc/native-php-template-engine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. earc/native-php-template-engine

ActiveLibrary

earc/native-php-template-engine
===============================

Native object oriented php template engine.

0.3(5y ago)079MITPHPPHP ^7.2 || ^8.0CI failing

Since Apr 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Koudela/eArc-native-php-template-engine)[ Packagist](https://packagist.org/packages/earc/native-php-template-engine)[ RSS](/packages/earc-native-php-template-engine/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

eArc-native-php-template-engine
===============================

[](#earc-native-php-template-engine)

Lightweight dependency free template component of the [earc framework](https://github.com/Koudela/eArc-core) for an [SOLID](https://en.wikipedia.org/wiki/SOLID) rendering approach.

Use the power of object-oriented programming to make your templates reusable and easy to understand.

table of Contents
-----------------

[](#table-of-contents)

- [Install](#install)
- [bootstrap](#bootstrap)
- [configure](#configure)
- [basic usage](#basic-usage)
    - [the template](#the-template)
    - [property logic](#property-logic)
    - [rendering](#rendering)
    - [rendering JSON objects](#rendering-json-objects)
- [helpers](#helpers)
    - [the template model interface](#the-template-model-interface)
    - [the collection template model](#the-collection-template-model)
    - [html](#html)
        - [attributes](#attributes)
        - [select](#select)
- [releases](#releases)
    - [release 0.3](#release-03)
    - [release 0.2](#release-02)
    - [release 0.1](#release-01)
    - [release 0.0](#release-00)

install
-------

[](#install)

```
$ composer require earc/native-php-template-engine
```

bootstrap
---------

[](#bootstrap)

The earc/native-php-template-engine does not require any bootstrapping.

configure
---------

[](#configure)

The earc/native-php-template-engine does not require any configuration.

basic usage
-----------

[](#basic-usage)

You can render `HTML`, `XML` and any other structured or unstructured output.

### the template

[](#the-template)

Templates are simple objects extending the `AbstractTemplateModel`. All the power of the object oriented programming can be used - even dependency injection.

The templates implement the `template` method. Everything echoed out inside this method will be the result of rendering the template. You can take advantage of the fact that php treats code outside of the php tags as plain output.

```
use eArc\NativePHPTemplateEngine\AbstractTemplateModel;

class MyTemplate extends AbstractTemplateModel
{
    /** @var object */
    protected $object;
    /** @var int */
    public $value;

    public function __construct(object $object, int $value)
    {
        $this->object = $object;
        $this->value = $value;
    }

    public function template() : void
    { ?>
        Hello World
        I have found a value ``.
        May be the object with the id ``
            can tell me what to do with it.

        I am fixed content.

                The iterables items are cast to string on rendering:
