Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cdb5ee0

Browse filesBrowse files
committed
Merge branch '2.8' into 3.4
* 2.8: Update twig_extension.rst Added missing chapters to TOC in file constraints reference
2 parents ad72eb3 + d93952a commit cdb5ee0
Copy full SHA for cdb5ee0

File tree

Expand file treeCollapse file tree

2 files changed

+31
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-3
lines changed
Open diff view settings
Collapse file

‎reference/constraints/File.rst‎

Copy file name to clipboardExpand all lines: reference/constraints/File.rst
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ form field.
2929
| | - `notReadableMessage`_ |
3030
| | - `uploadIniSizeErrorMessage`_ |
3131
| | - `uploadFormSizeErrorMessage`_ |
32+
| | - `uploadPartialErrorMessage`_ |
33+
| | - `uploadNoFileErrorMessage`_ |
34+
| | - `uploadNoTmpDirErrorMessage`_ |
35+
| | - `uploadCantWriteErrorMessage`_ |
36+
| | - `uploadExtensionErrorMessage`_ |
3237
| | - `uploadErrorMessage`_ |
3338
| | - `payload`_ |
3439
+----------------+---------------------------------------------------------------------+
Collapse file

‎templating/twig_extension.rst‎

Copy file name to clipboardExpand all lines: templating/twig_extension.rst
+26-3Lines changed: 26 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
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 array(
37-
new TwigFilter('price', array($this, 'priceFilter')),
37+
new TwigFilter('price', array($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;
@@ -55,9 +55,32 @@ Create a class that extends ``AbstractExtension`` and fill in the logic::
5555
versions before 1.26, include this method which is omitted in the example
5656
above.
5757

58+
Here's how to create a custom **function**::
59+
60+
// src/AppBundle/Twig/AppExtension.php
61+
namespace AppBundle\Twig;
62+
63+
use Twig\Extension\AbstractExtension;
64+
use Twig\TwigFunction;
65+
66+
class AppExtension extends AbstractExtension
67+
{
68+
public function getFunctions()
69+
{
70+
return array(
71+
new TwigFunction('area', array($this, 'calculateArea')),
72+
);
73+
}
74+
75+
public function calculateArea(int $width, int $length)
76+
{
77+
return $width * $length;
78+
}
79+
}
80+
5881
.. tip::
5982

60-
Along with custom filters, you can also add custom `functions`_ and register
83+
Along with custom filters and functions, you can also register
6184
`global variables`_.
6285

6386
Register an Extension as a Service

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.