Skip to content

Commit

Permalink
Merge pull request #8346 from kenjis/fix-parser-filter-default
Browse files Browse the repository at this point in the history
docs: fix Parser filter `default` explanation
  • Loading branch information
kenjis authored Dec 20, 2023
2 parents 36fd0ee + 5d9dc9b commit 3c75ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions tests/system/View/ParserFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,20 @@ public function testDefault(): void
$parser = new Parser($this->config, $this->viewsDir, $this->loader);

$data = [
'value1' => null,
'value2' => 0,
'value3' => 'test',
'value1' => '',
'value2' => null,
'value3' => 0,
'value4' => 'test',
];

$template = '{ value1|default(foo) } { value2|default(bar) } { value3|default(baz) }';
$template = '{ value1|default(foo) } { value2|default(bar) } { value3|default(baz) }'
. ' { value4|default(boo) } { undef|default(far) }';

$parser->setData($data);
$this->assertSame('foo bar test', $parser->renderString($template));
$this->assertSame(
'foo bar baz test { undef|default(far) }',
$parser->renderString($template)
);
}

public function testEsc(): void
Expand Down
5 changes: 3 additions & 2 deletions user_guide_src/source/outgoing/view_parser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ date format (Y-m-d) A PHP **date**-compatible formatting string.
date_modify value to add A **strtotime** compatible string to modify the date, { v|date_modify(+1 day) }
/ subtract like ``+5 day`` or ``-1 week``.

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

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

.. _empty(): https://www.php.net/manual/en/function.empty.php

See `PHP's NumberFormatter <https://www.php.net/manual/en/numberformatter.create.php>`_ for details relevant to the
"local_number" filter.

Expand Down

0 comments on commit 3c75ca5

Please sign in to comment.