Get param in url and use in page

Hello

Is it possible to retrieve a parameter from a page’s URL and use it in the generated page ?

Example when I go to http:///settings/pages/layout/page_testGetParam?day=2026-30-07

version: 1
pages:
  page_testGetParam:
    tags: []
    props:
      parameters: []
      parameterGroups: []
    component: oh-layout-page
    config:
      layoutType: fixed
      fixedType: canvas
      label: test GetParam
    slots:
      default: []
      masonry: []
      grid: []
      canvas:
        - component: oh-canvas-layer
          config: {}
          slots:
            default:
              - component: oh-canvas-item
                config:
                  x: 20
                  y: 19
                  h: 150
                  w: 659
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        label: =new URLSearchParams(window.location.search).get('day') #not work! display "Error: 'URLSearchParams' is not a function"

Will display 2026-30-07

The goal is to display the weather forecast for the specified day

The widget expressions are a parsed by a “javascript-like expression parser”, they are not true javascript so you don’t have access to the window context or complex JS classes.

The OH native way to do this is to open the page in question using the navigate action from a widget. When you do that you can configure the actionPageDefineVars parameter:

When you do that the keys of that object will be variable that you can access in widget expressions using the vars object. For example:

action: navigate
actionPage: page:page_testGetParam
actionPageDefineVars:
  day: =dayjs().format('YYYY-DD-MM')

would mean that the page could use vars.day to get today’s date in Y-D-M format

label: =vars.day

Thanks, that lets me do exactly what I wanted to do

I just had to replace

actionPage: page_testGetParam
#by
actionPage: page:page_testGetParam

for it to work

Sorry, my bad. Typing too quickly. Glad you caught the omission.