Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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