macfja/phptransformer-twital

Twital implementation of PhpTransformer

dev-master 2015-12-27 09:25 UTC

This package is auto-updated.

Last update: 2024-12-17 01:44:59 UTC


README

Twital support for PHPTransformers.

Install

Via Composer

$ composer require macfja/phptransformer-twital

Usage

$engine = new TwitalTransformer();
echo $engine->render('Hello, {{ name }}!', array('name' => 'phptransformers');

Special case for string rendering (render)

If you are using TwitalTransformer to render template stored in a string variable, you need to indicate to Twital plugin the type of string you are about to use (HTML5, XML, XHTML).
To do so you can pass a magic parameter to the render function. The parameter is named __twital-adapter and its value is an instance of \Goetas\Twital\SourceAdapter

$engine = new TwitalTransformer();
echo $engine->render(
    '<ul t:if="users">
        <li t:for="user in users">
            {{ user.name }}
        </li>
    </ul>',
    array(
        'users' => array(
            array('name' => 'phptransformers'),
            array('name' => 'twig'),
            array('name' => 'twital')
        ),
        '__twital-adapter' => new HTML5Adapter()
    )
);

Testing

$ phpunit

License

The MIT License (MIT). Please see License File for more information.