@@ -2617,7 +2617,9 @@ definition::
2617
2617
2618
2618
Then the ``query `` value will appear in the URL like ``https://my.domain/search?q=my+query+string ``.
2619
2619
2620
- If you need to change the parameter name on a specific page, you can leverage the :ref: `modifier <modifier >` option::
2620
+ If you need to change the parameter name on a specific page, you can leverage the :ref: `modifier <modifier >` option
2621
+ which takes a reference to a public function in your component that takes the ``LiveProp `` and the ``name ``
2622
+ of the property and must return a modified ``LiveProp `` object::
2621
2623
2622
2624
// ...
2623
2625
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
@@ -2629,27 +2631,28 @@ If you need to change the parameter name on a specific page, you can leverage th
2629
2631
public string $query = '';
2630
2632
2631
2633
#[LiveProp]
2632
- public ? string $alias = null ;
2634
+ public string $urlPrefix = '' ;
2633
2635
2634
- public function modifyQueryProp(LiveProp $liveProp): LiveProp
2636
+ public function modifyQueryProp(LiveProp $liveProp, string $propName ): LiveProp
2635
2637
{
2636
- if ($this->alias) {
2637
- $liveProp = $liveProp->withUrl(new UrlMapping(as: $this->alias));
2638
- }
2639
- return $liveProp;
2638
+ return $this->urlPrefix
2639
+ ? $liveProp->withUrl(new UrlMapping($this->urlPrefix . ucfirst($propName)))
2640
+ : $liveProp;
2640
2641
}
2641
2642
}
2642
2643
2643
2644
.. code-block :: html+twig
2644
2645
2645
- <twig:SearchModule alias="q" />
2646
+ <twig:SearchModule urlPrefix="example" />
2647
+
2648
+ Now the ``query `` value will appear in the URL like: ``https://my.domain/search?exampleQuery ``
2646
2649
2647
2650
This way you can also use the component multiple times in the same page and avoid collisions in parameter names:
2648
2651
2649
2652
.. code-block :: html+twig
2650
2653
2651
- <twig:SearchModule alias="q1 " />
2652
- <twig:SearchModule alias="q2 " />
2654
+ <twig:SearchModule urlPrefix="example1 " />
2655
+ <twig:SearchModule urlPrefix="example2 " />
2653
2656
2654
2657
Validating the Query Parameter Values
2655
2658
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments