Commit cddafa8
committed
minor #2456 [TwigComponent] Document about unwanted behavior with
This PR was merged into the 2.x branch.
Discussion
----------
[TwigComponent] Document about unwanted behavior with `ExposeInTemplate` and computed methods
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- For new features, provide some code snippets to help understand usage.
- Features and deprecations must be submitted against branch main.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
As spotted when working on my application, the following code triggers two times the methods `transactions()` because of the presence of `#[ExposeInTemplate]` (because before I used `transactions` instead of `computed.transactions`):
```php
#[ExposeInTemplate]
public function transactions(): array
{
// SQL query to database
}
```
```twig
{{ computed.transactions|length }}
```
When I remove `#[ExposeInTemplate]`, then only one SQL query is made.
Commits
-------
16cd48a [TwigComponent] Document about unwanted behavior with ExposeInTemplate and computed methodsExposeInTemplate and computed methods (Kocal)1 file changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
| 385 | + | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| |||
1553 | 1553 | | |
1554 | 1554 | | |
1555 | 1555 | | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
1556 | 1562 | | |
1557 | 1563 | | |
1558 | 1564 | | |
| |||
0 commit comments