You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this point you can now begin using twig like you would any other view
25
+
Create your Twig file in `resources/views` with the `.twig` file extension, for example:
29
26
30
-
```php
31
-
//app/Http/routes.php
32
-
//twig template resources/views/hello.twig
33
-
Route::get('/', function () {
34
-
return View::make('hello');
35
-
});
27
+
```html
28
+
<!-- resources/views/welcome.twig -->
29
+
<h1>
30
+
Welcome to TwigBridge!
31
+
</h1>
36
32
```
37
33
38
-
You can create the twig files in resources/views with the .twig file extension.
39
-
```bash
40
-
resources/views/hello.twig
34
+
At this point, you can now begin using Twig like you would any other view:
35
+
36
+
```php
37
+
// routes/web.php
38
+
39
+
use Illuminate\Support\Facades\Route;
40
+
41
+
Route::get('/', static function () {
42
+
return view('welcome');
43
+
});
41
44
```
42
45
43
46
# Configuration
44
47
45
-
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:
48
+
## Automatic
49
+
50
+
**For Modern Laravel (5.5+):** Laravel automatically registers the Service Provider and Facade through Package Auto-Discovery. **Manual registration in `config/app.php` is not required**, and you can skip directly to publishing the configuration file below.
51
+
52
+
## Manual
53
+
54
+
**For Legacy Laravel (5.4 and below):** If you are using an older version of Laravel without Package Auto-Discovery support, you need to register TwigBridge manually
55
+
56
+
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:
46
57
47
58
```php
48
59
'TwigBridge\ServiceProvider',
49
60
```
50
61
51
-
You can add the TwigBridge Facade, to have easier access to the TwigBridge (or Twig\Environment).
62
+
You can add the TwigBridge Facade to have easier access to the TwigBridge (or Twig\Environment).
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`.
73
+
## Publishing Configuration
63
74
64
-
You _should_ use Artisan to copy the default configuration file from the `/vendor` directory to `/config/twigbridge.php` with the following command:
75
+
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`.
65
76
66
-
```bash
77
+
You *should* use Artisan to copy the default configuration file from the `/vendor` directory to `/config/twigbridge.php` with the following command:
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.
83
+
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.
71
84
72
85
# Installation on Lumen
73
86
74
-
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.
87
+
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.
75
88
Copy the `config/twigbridge.php` file to your local `config` folder and register the configuration + Service Provider in `bootstrap/app.php`:
76
89
77
90
```php
@@ -117,15 +130,15 @@ And output variables, escaped by default. Use the `raw` filter to skip escaping.
117
130
118
131
# Extensions
119
132
120
-
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.
133
+
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.
121
134
122
135
```php
123
136
'enabled' => array(
124
137
'TwigBridge\Extensions\Example'
125
138
)
126
139
```
127
140
128
-
TwigBridge supports both a string or a closure as a callback, so for example you might implement the [Assetic](https://github.com/kriswallsmith/assetic) Twig extension as follows:
141
+
TwigBridge supports both a string or a closure as a callback, so for example, you might implement the [Assetic](https://github.com/kriswallsmith/assetic) Twig extension as follows:
129
142
130
143
```php
131
144
'enabled' => [
@@ -140,7 +153,7 @@ TwigBridge supports both a string or a closure as a callback, so for example you
140
153
141
154
TwigBridge comes with the following extensions enabled by default:
@@ -164,52 +177,55 @@ To enable '0.5.x' style Facades, enable the Legacy Facades extension:
164
177
165
178
These loader extensions exposes Laravel helpers as both Twig functions and filters.
166
179
167
-
Check out the config/twigbridge.php file to see a list of defined function / filters. You can also add your own.
180
+
Check out the `config/twigbridge.php` file to see a list of defined functions/filters. You can also add your own.
168
181
169
182
## FacadeLoader
170
183
171
-
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.
184
+
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.
172
185
173
186
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)`)
174
187
175
188
## Functions/Filters/Variables
176
189
177
-
The following helpers/filters are added by the default Extensions. They are based on the helpers and/or facades, so should be self explaining.
0 commit comments