Skip to content

Commit

Permalink
{% exit %} message param
Browse files Browse the repository at this point in the history
Resolves #13166
  • Loading branch information
brandonkelly committed May 8, 2023
1 parent db9d07b commit cdc0399
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Development
- Added a new `_globals` global Twig variable for front-end templates, which can be used to store custom values in a global scope. ([#13050](https://github.com/craftcms/cms/pull/13050), [#12951](https://github.com/craftcms/cms/discussions/12951))
- The `|replace` Twig filter now supports passing in a hash with regular expression keys. ([#12956](https://github.com/craftcms/cms/issues/12956))
- `{% exit %}` tags now support passing a message after the status code. ([#13166](https://github.com/craftcms/cms/discussions/13166))
- Elements now include custom field values when being iterated over, and when being merged. ([#13009](https://github.com/craftcms/cms/issues/13009))
- Dropdown and Radio Buttons fields now have a “Column Type” setting, which will be set to `varchar` for existing fields, and defaults to “Automatic” for new fields. ([#13025](https://github.com/craftcms/cms/pull/13025), [#12954](https://github.com/craftcms/cms/issues/12954))

Expand Down
11 changes: 9 additions & 2 deletions src/web/twig/nodes/ExitNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ public function compile(Compiler $compiler): void

if ($class === HttpException::class) {
$compiler
->write("throw new $class($status);\n");
->write("throw new $class($status");
if ($this->hasNode('message')) {
$compiler->raw(', ');
}
} else {
$compiler
->write("throw new $class();\n");
->write("throw new $class(");
}
if ($this->hasNode('message')) {
$compiler->subcompile($this->getNode('message'));
}
$compiler->raw(");\n");
} else {
$compiler->write(Craft::class . "::\$app->end();\n");
}
Expand Down
4 changes: 4 additions & 0 deletions src/web/twig/tokenparsers/ExitTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function parse(Token $token): ExitNode

if ($stream->test(Token::NUMBER_TYPE)) {
$nodes['status'] = $parser->getExpressionParser()->parseExpression();

if (!$stream->test(Token::BLOCK_END_TYPE)) {
$nodes['message'] = $parser->getExpressionParser()->parseExpression();
}
}

$stream->expect(Token::BLOCK_END_TYPE);
Expand Down

0 comments on commit cdc0399

Please sign in to comment.