Download the PHP package barryvdh/laravel-twigbridge without Composer
On this page you can find all versions of the php package barryvdh/laravel-twigbridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-twigbridge
Laravel 4 TwigBridge
Note: This package is deprecated in favor of https://github.com/rcrowe/TwigBridge. Please try the 0.6.x release, which should be very similar and provide the same functionality. Further progress will take place there.
This packages adds Twig as a Laravel Template Engine:
- Use .twig files just like Blade/PHP Templates
- Supports creator/composer events
- Easily add helpers/filters (
{{ url('/') }}
or{{ 'someThing' | snake_case }}
) - Can call Facades (
{{ MyModel.to('/') }}
) - Can be integrated with Assetic (https://github.com/barryvdh/laravel-assetic)
- Default extensions for easier use.
See http://twig.sensiolabs.org/ for more info about Twig Templating
Install
Require this package in your composer.json and run composer update (or run composer require barryvdh/laravel-twigbridge:dev-master
directly):
"barryvdh/laravel-twigbridge": "0.3.x"
After updating composer, add the ServiceProvider to the providers array in app/config/app.php
You can add the Twig Facade to have easy access to Twig_Environment, ie. Twig::render('template.twig')
.
Usage
After install, you can just use View::make('index'); 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.
Extensions
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:
- asset, action, url, route, secure_url, secure_asset
- link_to, link_to_asset, link_to_route, link_to_action
- auth_check, auth_guest, auth_user
- config_get, config_has
- session_has, session_get, csrf_token
- trans, trans_choice
- form_ (All the Form:: methods, snake_cased)
- html_ (All the Html:: methods, snake_cased)
- str_ (All the Str:: methods, snake_cased)
- url_ (All the URL:: methods, snake_cased)
Filters:
- camel_case, snake_case, studly_case
- str_ (All the Str:: methods, snake_cased)
Global variables:
- app: the Illuminate\Foundation\Application object
- errors: The $errors MessageBag from the Validator (always available)
Example Template Syntax
In a Blade template, if you had a route to edit a task in a Task/Todo application, you would use the following syntax to link to a route.
{{ link_to_route('tasks.edit', 'Edit', $task->id, array('class' => 'btn btn-primary')) }}
In a Twig template you would do the same thing using the following syntax. Notice the task object drops the dollar sign ($
) and instead of an arrow (->
) you use a period ('.'
). Also, you convert the array to a Python/Javascript dictionary type syntax.
{{ link_to_route('tasks.edit', 'Edit', task.id, {'class': 'btn btn-primary'}) }}
Commands
2 Artisan commands are included:
$ php artisan twig:clear
- Clear the compiled views in the Twig Cache
$ php artisan twig:lint <dir or filename>
- Check a directory or file for Twig errors, for exampele
php artisan twig:lint app/views
- Check a directory or file for Twig errors, for exampele
Configure
To publish a configuration file, you can run the following command:
Change your config to choose what helpers/filters you want to use, and what Facades to register. You can also pass in a callback or array to define options. You can also use an instance of Twig_SimpleFunction or Twig_SimpleFilter. Besides facades, you can also add your Models.
Extend
The Twig_Environment is available as 'twig' in the App Container, so you can access it via app('twig') or App::make('twig'). The ChainLoader is 'twig.loader', the array templates are in 'twig.templates'. You can also use the Twig Facade to access the Twig_Environment functions directly.
All versions of laravel-twigbridge with dependencies
illuminate/support Version 4.x
illuminate/view Version 4.x
twig/twig Version ~1.12
symfony/twig-bridge Version >=2.3