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
This PR was squashed before being merged into the 1.x branch.
Discussion
----------
More PHPUnit fixes
Commits
-------
f787c032 Migrate more tests
ad8d012e Update phpunit config
This PR was merged into the 2.x branch.
Discussion
----------
Fixed Twig\Template check
Looks like this was missed when the `Twig\Template` class was added, and `Twig_Template` was deprecated + aliased.
Commits
-------
67bff7b7 Fixed Twig\Template check
This PR was merged into the 3.x branch.
Discussion
----------
Added return and argument type for LoaderInterface
@fabpot I have started with my preparation for the Twig Certification. Here I found some missing return and argument type at the DatabaseTwigLoader example. Hopefully I fix everything corrent. I couldn't found a CONTRIBUTING.md or anything else.
Commits
-------
5521e034 Added return and argument type for LoaderInterface
This PR was merged into the 2.x branch.
Discussion
----------
Macro not available in embed tags
Macro imported globally in a template via `import` or `from` are not available inside `embed` tags.
This behavior is present since Twig v2.0.0. I think it needs to be documented. Feel free to suggest an other text.
Here is some example :
- If the macro is imported globally, it's not available inside the `embed` tag, we get an error : https://twigfiddle.com/jwtwm3
```twig
{% import 'macro.twig' as macro %}
{% embed 'embed.twig' %}
{% block content %}
{{ macro.sayhello('Jérôme') }}
{% endblock %}
{% endembed %}
```
- Whereas is the macro is imported inside the `embed` tag, it's available in its `block` tags : https://twigfiddle.com/jwtwm3/2
```twig
{% embed 'embed.twig' %}
{% import 'macro.twig' as macro %}
{% block content %}
{{ macro.sayhello('Jérôme') }}
{% endblock %}
{% endembed %}
```
Commits
-------
be291441 Update doc for macro with embed tags
This PR was merged into the 2.x branch.
Discussion
----------
Fix compatibility with PHPUnit 9
Commits
-------
9a83f7ed Fix compatibility with PHPUnit 10