Hi everyone,
i should pass 2 parameters from my index page to the search page using the values to filter the query.
What is the most correct way to handle this case?
Doing it with parameters in the url I think is wrong as I should make a routing rule of the type search/:key/:category but since these parameters are optional the routing rule would not be satisfied.
Thanks for support Sid…
I set the query params I need in the main template
I set the routing rule with optional parameters
I changed the do route code on the page
I entered the parameters in the button link
But when the url that is generated is wrong, maybe I don’t pass the values of the textbox and the select well in the link?
Is there any special formatting for passing values in query params?
The HREF attribute you are using is regular HTML attribute. Because you need to supply dynamic data, you need to use dmx-bind:href attribute.
Check the dynamic attribute option in the UI, and setup source from there. Be sure to remove the current href attribute.
Also, generally, any regular attribute on a tag can be made dynamic by appending dmx-bind: to it.
Perfect, now works fine!
I am left with one last problem, I made 2 optional parameters like this /page/:tag?/:category?
but if the first parameter is not valued, how could I solve the error page? Do I need to create multiple routing rules?
The way optional parameters work is that you can skip them from right to left… but never in the middle.
So, with /page/:tag?/:category?, valid URLs are:
/page
/page/some-tag
/page/some-tag/some-cat
If you want, you can swap the two to have category, but not tag - /page/:category?/:tag?
If you want either of them as optional, you cannot use routing params. You will have to use regular query params using ?.
@ben can help I suppose. It does not require any configuration if you live in the code view.
You can just use query.paramname in your bindings, and it will work.