-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1442 [Twig] Add (alternate) attribute rendering system (kbond)
This PR was merged into the 2.x branch. Discussion ---------- [Twig] Add (alternate) attribute rendering system | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Issues | n/a | License | MIT This is an alternate to #1404 as suggested by Ryan [here](#1404 (comment)). This PR allows the following: ```twig <div class="{{ attributes.render('class') }} appended-default" style="prepended-default {{ attributes.render('style') }}" data-foo="{{ attributes.render('data-foo')|default('replaced-default') }}" {{ attributes }} > ``` When calling `attributes.render('name')` ~(or magically via `attributes.name`)~, the attribute is marked as _rendered_. Later when calling just `{{ attributes }}`, the attributes marked as already rendered are excluded. Whether or not an attribute is considered rendered is only evaluated when converting `ComponentAttributes` to a string. TODO: - [x] Docs - [x] Add test ensuring works in real twig component Commits ------- 0d027d5 feat(twig): Add attribute rendering system
- Loading branch information
Showing
6 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/TwigComponent/tests/Fixtures/templates/components/RenderAttributes.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div | ||
foo="{{ attributes.render('foo') }}" | ||
bar="{{ attributes.render('bar')|default('default') }}" | ||
baz="default {{ attributes.render('baz') }}" | ||
qux="{{ attributes.render('qux') }} default" | ||
{{ attributes }} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters