Skip to content

Commit 15c6be8

Browse files
committed
Tweaked the method names
1 parent ccbd178 commit 15c6be8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

templating/twig_extension.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ Create a class that extends ``AbstractExtension`` and fill in the logic::
3434
public function getFilters()
3535
{
3636
return [
37-
new TwigFilter('price', [$this, 'priceFilter']),
37+
new TwigFilter('price', [$this, 'formatPrice']),
3838
];
3939
}
4040

41-
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
41+
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
4242
{
4343
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
4444
$price = '$'.$price;
@@ -111,7 +111,7 @@ be significant.
111111

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

117117
// src/AppBundle/Twig/AppExtension.php
@@ -127,14 +127,14 @@ callable defined in ``getFilters()``::
127127
{
128128
return [
129129
// the logic of this filter is now implemented in a different class
130-
new TwigFilter('price', [AppRuntime::class, 'priceFilter']),
130+
new TwigFilter('price', [AppRuntime::class, 'formatPrice']),
131131
];
132132
}
133133
}
134134

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

139139
// src/AppBundle/Twig/AppRuntime.php
140140
namespace AppBundle\Twig;
@@ -149,7 +149,7 @@ previous ``priceFilter()`` method::
149149
// extensions, you'll need to inject services using this constructor
150150
}
151151

152-
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
152+
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
153153
{
154154
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
155155
$price = '$'.$price;

0 commit comments

Comments
 (0)