shapecode/twig-string-loader

1.0.0 2019-07-03 09:15 UTC

This package is auto-updated.

Last update: 2021-09-26 09:57:56 UTC


README

paypal

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads License

Install instructions

First you need to add shapecode/twig-string-loader to composer.json:

Do it by execute composer require shapecode/twig-string-loader or do it manually

{
   "require": {
        "shapecode/twig-string-loader": "^1.0"
    }
}

Add the string loader to your $twig object

<?php

// index.php
//...

$loader1 = new \Twig\Loader\FilesystemLoader('/path/to/templates');
$loader2 = new \Shapecode\Twig\Loader\StringLoader();
$loader = new \Twig\Loader\ChainLoader([$loader1, $loader2]);

$twig = new \Twig\Environment($loader);

Usage

Now you can compile strings with twig:

<?php

$twig->render('Hello {{ world }}', array(
    'world' => 'World'
));