Skip to content

Commit e606b13

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: Correct method name in example
2 parents 38e5055 + 15c6be8 commit e606b13

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

templating/twig_extension.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ be significant.
133133

134134
That's why Twig allows to decouple the extension definition from its
135135
implementation. Following the same example as before, the first change would be
136-
to remove the ``priceFilter()`` method from the extension and update the PHP
136+
to remove the ``formatPrice()`` method from the extension and update the PHP
137137
callable defined in ``getFilters()``::
138138

139139
// src/Twig/AppExtension.php
@@ -149,14 +149,14 @@ callable defined in ``getFilters()``::
149149
{
150150
return [
151151
// the logic of this filter is now implemented in a different class
152-
new TwigFilter('price', [AppRuntime::class, 'priceFilter']),
152+
new TwigFilter('price', [AppRuntime::class, 'formatPrice']),
153153
];
154154
}
155155
}
156156

157157
Then, create the new ``AppRuntime`` class (it's not required but these classes
158158
are suffixed with ``Runtime`` by convention) and include the logic of the
159-
previous ``priceFilter()`` method::
159+
previous ``formatPrice()`` method::
160160

161161
// src/Twig/AppRuntime.php
162162
namespace App\Twig;
@@ -171,7 +171,7 @@ previous ``priceFilter()`` method::
171171
// extensions, you'll need to inject services using this constructor
172172
}
173173

174-
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
174+
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
175175
{
176176
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
177177
$price = '$'.$price;

0 commit comments

Comments
 (0)