PHP code example of barryvdh / laravel-twigbridge

1. Go to this page and download the library: Download barryvdh/laravel-twigbridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

barryvdh / laravel-twigbridge example snippets


'Barryvdh\TwigBridge\ServiceProvider',

'Twig' => 'Barryvdh\TwigBridge\Twig',

View::composer('profile', function($view)
{
	$view->with('count', User::count());
});

'functions' => array(
	'simple_function',
	'class_function' => 'MyClass@method',
	'other_function' => array(
		'is_safe' => array('html')
	),
	'call_me' => array(
		'is_safe' => array('html'),
		'callback' => function($value){ 
				return phone($value);
			}
	)
),

'filters' => array(
	'filter_this' => function($value){
			return doSomething($value);
		}
),

'facades' => array(
	'Auth', 
	'MyModel'
)

//Using the App container
$twig = app('twig');
$twig->addFunction(new Twig_SimpleFunction(..));

$loader = App::make('twig.loader');
$loader->addLoader($myLoader);

//Using the Facade
Twig::addGlobal('key', $value);
Twig::addFunction(new Twig_SimpleFunction(..));
Twig::getLoader()->addLoader($myLoader);

//Adding templates to the array loader
App::extend('twig.templates', function($templates){
        $templates['hello'] = 'Hello World!';
        return $templates;
    });
echo Twig::render('hello'); //Hello World!
 

$ php artisan config:publish barryvdh/laravel-twigbridge