This packages adds Twig as a Laravel Template Engine:
{{ url('/') }}
or {{ 'someThing' | snake_case }}
){{ MyModel.to('/') }}
)See http://twig.sensiolabs.org/ for more info about Twig Templating
Require this package in your composer.json and run composer update (or run composer require barryvdh/laravel-twigbridge:dev-master
directly):
"barryvdh/laravel-twigbridge": "dev-master"
After updating composer, add the ServiceProvider to the providers array in app/config/app.php
'Barryvdh\TwigBridge\ServiceProvider',
You can add the Twig Facade to have easy access to Twig_Environment, ie. Twig::render('template.twig')
.
'Twig' => 'Barryvdh\TwigBridge\Twig',
After install, you can just use View::make('index');
or Twig::render('index.twig', $data)
The .twig extension should be omitted in the View::make() call, just like Blade files. Within your Twig files, you can reference them with or without .twig.
You can also use view composers/creators, just like in Blade templates.
View::composer('profile', function($view)
{
$view->with('count', User::count());
});
The following helpers/filters are added by the default Extensions. They are based on the helpers and/or facades, so should be self explaining.
Functions:
Filters:
Global variables:
This package has been deprecated in favor of http://github.com/rcrowe/TwigBridge version 0.6.0 Syntax and features are all available in this new version, just have to replace the config file.
This is the result of combining our work to make a more robust/tested/extendable twig bridge :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community