shapecode/twig-string-loader

A string loader for twig

2.0.0 2023-12-02 15:19 UTC

This package is auto-updated.

Last update: 2024-03-31 16:02:44 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'
));