Skip to content

shapecode/twig-string-loader

Repository files navigation

Shapecode - Twig String Loader

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'
));