Download the PHP package synergitech/twigbridge without Composer
On this page you can find all versions of the php package synergitech/twigbridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download synergitech/twigbridge
More information about synergitech/twigbridge
Files in synergitech/twigbridge
Package twigbridge
Short Description Adds the power of Twig to Laravel
License MIT
Informations about the package twigbridge
TwigBridge
this is a fork that has been updated with various fixes, it will be kept up to date with any changes from upstream
Allows you to use Twig seamlessly in Laravel (>= 6).
If you need to use an older version of Laravel, have a look at the original rcrowe/TwigBridge
Installation
Laravel should automatically detect the service provider and facade but you should add the config file with artisan:
Laravel automatically registers the Service Provider. Use Artisan to publish the twig config file:
Installation on Lumen
For Lumen, you need to load the same Service Provider but you have to disable the Auth
, Translator
, and Url
extensions in your local configuration.
Copy the config/twigbridge.php
file to your local config
folder and register the configuration and Service Provider in bootstrap/app.php
:
Usage
At this point you can now begin using twig like you would any other view
You can create the twig files in resources/views with the .twig
file extension.
You call the Twig template like you would any other view:
TwigBridge also supports views in other packages:
The above rules continue when extending another Twig template:
You can call functions with parameters:
And output variables, escaped by default. Use the raw
filter to skip escaping.
Extensions
Sometimes you want to extend / add new functions for use in Twig templates. Add to the enabled
array in config/twigbridge.php a list of extensions for Twig to load.
TwigBridge supports both a string or a closure as a callback, so for example you might implement the Assetic Twig extension as follows:
TwigBridge comes with the following extensions enabled by default:
- Twig\Extension\DebugExtension
- TwigBridge\Extension\Laravel\Auth
- TwigBridge\Extension\Laravel\Config
- TwigBridge\Extension\Laravel\Dump
- TwigBridge\Extension\Laravel\Form
- TwigBridge\Extension\Laravel\Gate
- TwigBridge\Extension\Laravel\Html
- TwigBridge\Extension\Laravel\Input
- TwigBridge\Extension\Laravel\Session
- TwigBridge\Extension\Laravel\String
- TwigBridge\Extension\Laravel\Translator
- TwigBridge\Extension\Laravel\Url
- TwigBridge\Extension\Loader\Facades
- TwigBridge\Extension\Loader\Filters
- TwigBridge\Extension\Loader\Functions
To enable '0.5.x' style Facades, enable the Legacy Facades extension:
- TwigBridge\Extension\Laravel\Legacy\Facades
FilterLoader and FunctionLoader
These loader extensions exposes Laravel helpers as both Twig functions and filters.
Check out the config/twigbridge.php file to see a list of defined function / filters. You can also add your own.
FacadeLoader
The FacadeLoader extension allows you to call any facade you have configured in config/twigbridge.php. This gives your Twig templates integration with any Laravel class as well as any other classes you alias.
To use the Laravel integration (or indeed any aliased class and method), just add your facades to the config and call them like URL.to(link)
(instead of URL::to($link)
)
Functions/Filters/Variables
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
- auth_check, auth_guest, auth_user
- can
- config_get, config_has
- dump
- form_ (All the Form:: methods, snake_cased)
- html_ (All the Html:: methods, snake_cased)
- input_get, input_old, input_has
- link_to, link_to_asset, link_to_route, link_to_action
- session_has, session_get, csrf_token, csrf_field, method_field
- str_ (All the Str:: methods, snake_cased)
- trans, trans_choice
- url_ (All the URL:: methods, snake_cased)
Filters:
- camel_case, snake_case, studly_case
- str_ (All the Str:: methods, snake_cased)
- trans, trans_choice
Global variables:
- app: the Illuminate\Foundation\Application object
- errors: The $errors MessageBag from the Validator (always available)
Artisan Commands
TwigBridge offers commands for CLI Interaction.
Empty the Twig cache:
Lint all Twig templates:
All versions of twigbridge with dependencies
twig/twig Version ^3.0
illuminate/support Version ^6|^7|^8|^9
illuminate/view Version ^6|^7|^8|^9