shapecode / twig-string-loader
A string loader for twig
                                    Fund package maintenance!
                                                                            
                                                                                                                                        nicklog
                                                                                    
                                                                            
                                                                                                                                        Liberapay
                                                                                    
                                                                            
                                                                                                                                        paypal.me/nloges
                                                                                    
                                                                
Installs: 116 269
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/shapecode/twig-string-loader
Requires
- php: ^8.1
 - twig/twig: ^3.8
 
Requires (Dev)
- doctrine/coding-standard: ^12.0
 - maglnet/composer-require-checker: ^4.7
 - phpstan/phpstan: ^1.10
 - phpstan/phpstan-deprecation-rules: ^1.1
 - phpstan/phpstan-phpunit: ^1.3
 - phpstan/phpstan-strict-rules: ^1.5
 - phpunit/phpunit: ^10.5
 - roave/security-advisories: dev-master
 - squizlabs/php_codesniffer: ^3.7
 
This package is auto-updated.
Last update: 2025-10-29 02:56:21 UTC
README
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' ));