You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #1396 [LiveComponent] Alias URL bound props (squrious)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[LiveComponent] Alias URL bound props
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| Issues | N/A
| License | MIT
Following symfony/ux#1230.
Allow custom parameter names for URL bound props, and mapping specification from Twig templates.
## Usage
From PHP definition:
```php
#[AsLiveComponent()]
final class MyComponent
{
// ...
#[LiveProp(writable: true, url: new QueryMapping(alias: 'q'))
public ?string $search = null;
}
```
From templates:
```twig
{{ component('MyComponent', {
'data-live-url-mapping-search': {
'alias': 'q'
}
})
}}
{{ component('MyComponent', { 'data-live-url-mapping-search-alias': 'q' }) }}
```
HTML syntax also works:
```twig
<twig:MyComponent :data-live-url-mapping-search="{ alias: 'q'}" />
<twig:MyComponent data-live-url-mapping-search-alias="q" />
```
## Result
Changing the value of `search` will update the url to `https://my.domain?q=my+search+string`.
Mappings provided in Twig templates are merged into those provided in PHP. Thus, query mappings in PHP act as defaults, and we can override them in templates (e.g. for specific page requirements). So a page with:
```twig
<twig:MyComponent/>
<twig:MyComponent data-live-url-mapping-search-alias="q" />
```
will update its URL to `http://my.domain?search=foo&q=bar`.
Commits
-------
828e34e5 [LiveComponent] Alias URL bound props
0 commit comments