cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Verceti87
Helper I
Helper I

How to request.params.id when no GUID is in URL?

As the title says how can I use

request.params.id?
1 ACCEPTED SOLUTION

Accepted Solutions
chleverenz
Super User
Super User

Hi @Verceti87 ,

the request.params collection contains the get parameters which are sent along with the request.

so, if the url is https://<myportalurl>/<myportalpage>/?a=42&vegetable=cucumber&cid=01234567-abcd-bcde-cdef-0123456789... the request.params collections can be accessed like this:

{% assign mya = request.params["a"] %} {%- comment -%}mya will contain 42 (as a string) now{%- endcomment -%}

{% assign myvegetable = request.params["vegetable"] %}{%- comment -%} myvegetable will contain the string cucumber{%- endcomment -%}

{% assign mycid = request.params["cid"] %}{%- comment -%} mycid will contain the string 01234567-abcd-bcde-cdef-0123456789ab{%- endcomment -%}

So, using request.params.id does not really make sense when the url does not contain a get parameter called id,

You can check the presence of the id by {% if request.params.id %} . May colleagues prefer {% assign myid = request.params.id | default: "noidpresent" %} and then somewhere in the code {% if myid = "noidpresent" %}...{% else%}...{%endif%}

Its a matter of taste and style 🙂

Hope this helps and is the answer to the question 🙂

   Christian

 

PS i never checked what happens if you pass in ...&a=1&a=2&a=3. I think, in asp.net you would get an array as parameters. But i never tried in portals. When i want wo pass in many values i usually use somtehing like ...&a=1,2,3 and somewhere in the code {% assign myas = request.params.a | split: "," %} to get an iterable for the a's  🙂

 

View solution in original post

2 REPLIES 2
chleverenz
Super User
Super User

Hi @Verceti87 ,

the request.params collection contains the get parameters which are sent along with the request.

so, if the url is https://<myportalurl>/<myportalpage>/?a=42&vegetable=cucumber&cid=01234567-abcd-bcde-cdef-0123456789... the request.params collections can be accessed like this:

{% assign mya = request.params["a"] %} {%- comment -%}mya will contain 42 (as a string) now{%- endcomment -%}

{% assign myvegetable = request.params["vegetable"] %}{%- comment -%} myvegetable will contain the string cucumber{%- endcomment -%}

{% assign mycid = request.params["cid"] %}{%- comment -%} mycid will contain the string 01234567-abcd-bcde-cdef-0123456789ab{%- endcomment -%}

So, using request.params.id does not really make sense when the url does not contain a get parameter called id,

You can check the presence of the id by {% if request.params.id %} . May colleagues prefer {% assign myid = request.params.id | default: "noidpresent" %} and then somewhere in the code {% if myid = "noidpresent" %}...{% else%}...{%endif%}

Its a matter of taste and style 🙂

Hope this helps and is the answer to the question 🙂

   Christian

 

PS i never checked what happens if you pass in ...&a=1&a=2&a=3. I think, in asp.net you would get an array as parameters. But i never tried in portals. When i want wo pass in many values i usually use somtehing like ...&a=1,2,3 and somewhere in the code {% assign myas = request.params.a | split: "," %} to get an iterable for the a's  🙂

 

Verceti87
Helper I
Helper I

@chleverenzThank you for the explanation.

Helpful resources

Announcements
Welcome Super Users.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (1,789)