Skip to content

Commit

Permalink
Merge pull request #8456 from kinglozzer/null-template-lookups
Browse files Browse the repository at this point in the history
Add support for null values in template lookups
  • Loading branch information
Sam Minnée committed Oct 12, 2018
2 parents 3190f6d + 3dcfc64 commit 102f9d1
Show file tree
Hide file tree
Showing 6 changed files with 1,633 additions and 1,542 deletions.
2 changes: 1 addition & 1 deletion docs/en/04_Changelogs/5.0.0.md
Expand Up @@ -16,7 +16,7 @@ guide developers in preparing existing 4.x code for compatibility with 5.0.
* `<% loop %>` and `<% with %>` now only ever result in one new scope level. For example
`<% loop $Pages.Limit(5) %>{$Up.Up.Title}<% end_loop %>` must be rewritten to use just one `$Up` statement to reach
the parent scope.
* Numeric and boolean values passed to methods in templates will now preserve their type, rather than
* Numeric, boolean and null values passed to methods in templates will now preserve their type, rather than
always being cast to strings. E.g. `$Foo(true)` would previously pass a string argument `'true'` to
“Foo”, but will now pass an actual boolean.

Expand Down
13 changes: 12 additions & 1 deletion src/View/SSTemplateParser.peg
Expand Up @@ -406,9 +406,13 @@ class SSTemplateParser extends Parser implements TemplateParser

QuotedString: q:/['"]/ String:/ (\\\\ | \\. | [^$q\\])* / '$q'

# Null

Null: / (null)\b /i

# Booleans

Boolean: / (true|false) /i
Boolean: / (true|false)\b /i

# Integers and floats

Expand Down Expand Up @@ -438,6 +442,7 @@ class SSTemplateParser extends Parser implements TemplateParser
Argument:
:DollarMarkedLookup |
:QuotedString |
:Null |
:Boolean |
:IntegerOrFloat |
:Lookup !(< FreeString)|
Expand Down Expand Up @@ -470,6 +475,12 @@ class SSTemplateParser extends Parser implements TemplateParser
$res['php'] = "'" . str_replace("'", "\\'", $sub['String']['text']) . "'";
}

function Argument_Null(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
$res['php'] = $sub['text'];
}

function Argument_Boolean(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
Expand Down

0 comments on commit 102f9d1

Please sign in to comment.