...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var params = new URLSearchParams(window.location.hash.split('?')[1]);
if(params.get('firstname') && params.get('lastname'))
{
value = params.get('firstname') + ' ' + params.get('lastname');
} |
The snippet above can be repurposed to for a variety of uses. It's helpful to understand the basic mechanics of this code:
- To set the values to a Component, you first need them accessible in the JavaScript. Line 1 can be copied verbatim into any similar rule code and is used to extract the parameters from the URL.
- Line 2 is making sure there is text provided in the elements you are working with. This may or may not be a necessary step depending on your use case. You will need to understand a bit about control the display of text when your objects don't alway exist. You can learn more about nulls, NaN, and undefined scenarios here.
- Line 4 assigns the firstname parameter and the lastname parameter to the Text component, and inserts a space between them.
For a working example of the scenario described, click here.