Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Slugify | 2,827 | 3,235 | 339 | 16 days ago | 41 | August 05, 2023 | 27 | mit | PHP | |
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte. | ||||||||||
Twigbridge | 877 | 410 | 77 | 7 months ago | 74 | February 10, 2022 | 94 | mit | PHP | |
Give the power of Twig to Laravel | ||||||||||
Marketplacekit | 668 | 9 months ago | 12 | August 23, 2019 | 105 | gpl-3.0 | PHP | |||
A platform to create an online marketplace | ||||||||||
Blade Extensions | 269 | 41 | 11 | 3 years ago | 43 | May 16, 2020 | 4 | other | PHP | |
Laravel Blade extensions like $loop->odd/$loop->index in foreach, view blocks and partials, etc | ||||||||||
Document Templates | 147 | 5 months ago | 28 | March 10, 2022 | 5 | mit | HTML | |||
Laravel package for creating and managing user editable document templates with placeholders and various data sources. | ||||||||||
Coyote | 78 | 6 days ago | 75 | mit | PHP | |||||
4programmers.net | ||||||||||
Laravel Twigbridge | 58 | 6 | 8 years ago | 8 | June 09, 2014 | 4 | PHP | |||
Laravel TwigBridge | ||||||||||
Laravel Assetic | 37 | 9 years ago | 1 | June 30, 2014 | 3 | PHP | ||||
Assetic ServiceProvider for Laravel | ||||||||||
Slim Laravel | 31 | 3 months ago | 1 | JavaScript | ||||||
A Laravel like base on Slim Framework 3. This is a skeleton app to start faster | ||||||||||
Core | 23 | 6 years ago | 1 | bsd-3-clause | PHP | |||||
:fire: Antares Core Implemenation. Most important project layer, this is the heart for your app. ACL, notifiter, console, geoip, areas, utils and many more... |
Allows you to use Twig seamlessly in Laravel.
TwigBridge >= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions.
Require this package with Composer
composer require rcrowe/twigbridge
Laravel automatically registers the Service Provider. Use Artisan to publish the twig config file:
php artisan vendor:publish --provider="TwigBridge\ServiceProvider"
At this point you can now begin using twig like you would any other view
//app/Http/routes.php
//twig template resources/views/hello.twig
Route::get('/', function () {
return View::make('hello');
});
You can create the twig files in resources/views with the .twig file extension.
resources/views/hello.twig
Once Composer has installed or updated your packages you need to register TwigBridge with Laravel itself. Open up config/app.php and find the providers key towards the bottom and add:
'TwigBridge\ServiceProvider',
You can add the TwigBridge Facade, to have easier access to the TwigBridge (or Twig\Environment).
'Twig' => 'TwigBridge\Facade\Twig',
Twig::addExtension('TwigBridge\Extension\Loader\Functions');
Twig::render('mytemplate', $data);
TwigBridge's configuration file can be extended in your ConfigServiceProvider, under the twigbridge
key. You can find the default configuration file at vendor/rcrowe/twigbridge/config
.
You should use Artisan to copy the default configuration file from the /vendor
directory to /config/twigbridge.php
with the following command:
php artisan vendor:publish --provider="TwigBridge\ServiceProvider"
If you make changes to the /config/twigbridge.php
file you will most likely have to run the twig:clean
Artisan command for the changes to take effect.
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 + Service Provider in bootstrap/app.php
:
$app->configure('twigbridge');
$app->register('TwigBridge\ServiceProvider');
You call the Twig template like you would any other view:
// Without the file extension
View::make('i_am_twig', [...])
TwigBridge also supports views in other packages:
View::make('pagination::simple')
The above rules continue when extending another Twig template:
{% extends "parent" %}
{% extends "pagination::parent" %}
You can call functions with parameters:
{{ link_to_route('tasks.edit', 'Edit', task.id, {'class': 'btn btn-primary'}) }}
And output variables, escaped by default. Use the raw
filter to skip escaping.
{{ some_var }}
{{ html_var | raw }}
{{ long_var | str_limit(50) }}
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.
'enabled' => array(
'TwigBridge\Extensions\Example'
)
TwigBridge supports both a string or a closure as a callback, so for example you might implement the Assetic Twig extension as follows:
'enabled' => [
function($app) {
$factory = new Assetic\Factory\AssetFactory($app['path'].'/../some/path/');
$factory->setDebug(false);
// etc.....
return new Assetic\Extension\Twig\AsseticExtension($factory);
}
]
TwigBridge comes with the following extensions enabled by default:
To enable '0.5.x' style Facades, enable the Legacy Facades extension:
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.
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)
)
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:
TwigBridge offers a command for CLI Interaction.
Empty the Twig cache:
$ php artisan twig:clean
Lint all Twig templates:
$ php artisan twig:lint