Skip to content

Commit 3c75ca5

Browse files
authored
Merge pull request #8346 from kenjis/fix-parser-filter-default
docs: fix Parser filter `default` explanation
2 parents 36fd0ee + 5d9dc9b commit 3c75ca5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

tests/system/View/ParserFilterTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,20 @@ public function testDefault(): void
109109
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
110110

111111
$data = [
112-
'value1' => null,
113-
'value2' => 0,
114-
'value3' => 'test',
112+
'value1' => '',
113+
'value2' => null,
114+
'value3' => 0,
115+
'value4' => 'test',
115116
];
116117

117-
$template = '{ value1|default(foo) } { value2|default(bar) } { value3|default(baz) }';
118+
$template = '{ value1|default(foo) } { value2|default(bar) } { value3|default(baz) }'
119+
. ' { value4|default(boo) } { undef|default(far) }';
118120

119121
$parser->setData($data);
120-
$this->assertSame('foo bar test', $parser->renderString($template));
122+
$this->assertSame(
123+
'foo bar baz test { undef|default(far) }',
124+
$parser->renderString($template)
125+
);
121126
}
122127

123128
public function testEsc(): void

user_guide_src/source/outgoing/view_parser.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ date format (Y-m-d) A PHP **date**-compatible formatting string.
371371
date_modify value to add A **strtotime** compatible string to modify the date, { v|date_modify(+1 day) }
372372
/ subtract like ``+5 day`` or ``-1 week``.
373373

374-
default default value Displays the default value if the variable is empty or { v|default(just in case) }
375-
undefined.
374+
default default value Displays the default value if the variable is `empty()`_. { v|default(just in case) }
376375

377376
esc html, attr, Specifies the context to escape the data. { v|esc(attr) }
378377
css, js
@@ -419,6 +418,8 @@ title Displays a "title case" version of the string
419418
upper Displays the string in all uppercase. { v|upper }
420419
================ ================= =========================================================== ======================================
421420

421+
.. _empty(): https://www.php.net/manual/en/function.empty.php
422+
422423
See `PHP's NumberFormatter <https://www.php.net/manual/en/numberformatter.create.php>`_ for details relevant to the
423424
"local_number" filter.
424425

0 commit comments

Comments
 (0)