@@ -2617,7 +2617,9 @@ definition::
26172617
26182618Then the ``query `` value will appear in the URL like ``https://my.domain/search?q=my+query+string ``.
26192619
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::
26212623
26222624 // ...
26232625 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
26292631 public string $query = '';
26302632
26312633 #[LiveProp]
2632- public ? string $alias = null ;
2634+ public string $urlPrefix = '' ;
26332635
2634- public function modifyQueryProp(LiveProp $liveProp): LiveProp
2636+ public function modifyQueryProp(LiveProp $liveProp, string $propName ): LiveProp
26352637 {
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;
26402641 }
26412642 }
26422643
26432644.. code-block :: html+twig
26442645
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 ``
26462649
26472650This way you can also use the component multiple times in the same page and avoid collisions in parameter names:
26482651
26492652.. code-block :: html+twig
26502653
2651- <twig:SearchModule alias="q1 " />
2652- <twig:SearchModule alias="q2 " />
2654+ <twig:SearchModule urlPrefix="example1 " />
2655+ <twig:SearchModule urlPrefix="example2 " />
26532656
26542657Validating the Query Parameter Values
26552658~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments