This PR was merged into the 1.x branch.
Discussion
----------
Enhancement: Use no_explicit_use_of_code_block_php rule
Commits
-------
87eb1396 Enhancement: Use no_explicit_use_of_code_block_php rule
This PR was merged into the 1.x branch.
Discussion
----------
Enhancement: Use GithubActions instead of Travis for tests
You can see the first run here: https://github.com/OskarStark/Twig/pull/3
Commits
-------
4438d4c1 Enhancement: Use GithubActions instead of Travis for tests
This PR was submitted for the 3.x branch but it was merged into the 1.x branch instead.
Discussion
----------
Fix `odd` not working for negative numbers
Fixes https://github.com/twigphp/Twig/issues/3424
Commits
-------
53a3ccd2 Fix `odd` not working for negative numbers
This PR was squashed before being merged into the 1.x branch.
Discussion
----------
Fix "include(template_from_string())" when not using a sandbox
Closed#3411
Commits
-------
df9c9f21 Fix "include(template_from_string())"
3d91e335 Fix PHPUnit config
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead.
Discussion
----------
[Documentation] Emphase the fact that the include tag outputs data
Commits
-------
ef6debec Emphase the fact that the include tag outputs data
This PR was submitted for the 3.x branch but it was merged into the 1.x branch instead.
Discussion
----------
Fix missing delimiter for preg_quote in lexer
Is is a really edge case (PHP < 7.3 and '#' as whitespace_trim symbol), but for the sake of consistency here's a proper fix.
Commits
-------
41605057 Fix missing delimiter for preg_quote in lexer
This PR was merged into the 1.x branch.
Discussion
----------
Add test to verify that filter is not working when template_from_string
When using {{ include(sandboxed = true) }} in conjunction with {{ template_from_string() }} - sandbox is not active.
Commits
-------
c7be1bb3 Fix sandbox support when using include(template_from_string())
04431228 Add test to verify that filter is not working when template_from_string is used.
This PR was squashed before being merged into the 1.x branch.
Discussion
----------
In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError
If a template accidentally performs `|filter(...)` on a variable that isn't traversable (e.g. `null`), the calling code will encouter the raw `TypeError` that results from Twig trying to construct an `IteratorIterator` on that variable. This means that context information (e.g., in which exact template the error occurred, and on which line) is discarded, which makes it very difficult to debug your templates.
This commit adds code to throw a `RuntimeError` if Twig encounters a situation where there's no valid way to filter an array.
Commits
-------
567b1e2a In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError
This PR was submitted for the 3.x branch but it was squashed and merged into the 1.x branch instead.
Discussion
----------
Make round brackets optional for one argument tests like sameas
Currently Twig forces round brackets when doing tests with `is` if there is an argument:
{{ 1 is same as(1) ? 'OK' }}
{{ 8 is divisible by(2) ? 'OK' }}
That syntax always bumped me, because without the brackets it would be easier to understand and write, especially for people who do not know Twig internals:
{{ 1 is same as 1 ? 'OK' }}
{{ 8 is divisible by 2 ? 'OK' }}
Twig only has the `same as` and `divisible by` tests which need arguments (in the base library), and for both you usually only need one argument, so it could make the template syntax more concise. [Jinja already supports this syntax](https://jinja.palletsprojects.com/en/2.11.x/templates/#tests) for one argument tests, so it would be one less difference between Jinja and Twig for people who use both.
The changes in this pull request should be fully backwards-compatible - instead of Twig throwing a SyntaxError it now accepts one argument when the round brackets are missing. I added an option for TwigTest to signal that there is one mandatory argument for the test, otherwise the ExpressionParser does not know it should look for that mandatory argument, and this feature is therefore available to anybody writing their own TwigTests, which could help extensions to Twig to simplify their syntax too.
I also adjusted the unit tests for `sameas` and `divisibleby` in hopefully a sensible way.
Commits
-------
1ee72d9e Make round brackets optional for one argument tests like sameas
This PR was submitted for the 3.x branch but it was merged into the 1.x branch instead.
Discussion
----------
Support object initialisation shortcut {a} == {a:a} from ES2015
Object declaration in Twig is very close to the Javascript syntax and is targeting the same profil of developers. In order to provide a smooth developer experience, Twig should implement some new feature of ECMAScript.
Since ECMAScript 2015, a short syntax can be used to declare an object when the key is identical to a defined variable (see [MDN doc](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer))
```js
// Shorthand property names (ES2015)
let a = 'foo', b = 42, c = {};
let o = {a, b, c}
```
This PR adds the same syntax to Twig.
This can be very useful for `include ... with ... only` :
```twig
{% set title = "My title" %}
{% set image = "image.jpg" %}
{{ include "template.twig" with {title, image} only }}
# instead of
{{ include "template.twig" with {title: title, image: image} only }}
```
Commits
-------
133edb36 Support object init from variable