shapecode/twig-string-loader

A string loader for twig

1.1.0 2022-01-15 12:43 UTC

This package is auto-updated.

Last update: 2023-01-15 14:49:38 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'
));