# Variables

{% hint style="info" %}
This feature requires a [PowerShell Universal license](https://docs.powershelluniversal.com/v3/licensing).&#x20;
{% endhint %}

Variables allow you modify the functionality of a page depending on factors such as the user name or URL route. Variable-based routes allow you to create dynamic pages based on the URL the user is visiting.&#x20;

Variables that are defined with Platform \ Variables will also be available to pages.

## Viewing Variables

Variables can be viewed when editing a page. To view variables, click Edit and then Variables.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FuDdM6xYScsag52kAXEg7%2Fimage.png?alt=media\&token=3f322a4e-9818-4c77-8273-ee2d3c93e0dd)

A drawer will appear with the variables for the current page.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FSnHuNmwMMeOmKtuSSUxj%2Fimage.png?alt=media\&token=45999be5-075d-4a48-b134-396bdda0b529)

## Using Variables

Variables can be used anywhere you can type a property value. For example, if you have an Alert, you could use the `$pagename` variable within the title property.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FciygoY3sjpewjEkMIOck%2Fimage.png?alt=media\&token=331644a8-a2ad-46b6-b5ee-c446b04f05fb)

When the page is rendered, the variable will be replaced.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2F8hhXiSgCm1t3xy66KX2H%2Fimage.png?alt=media\&token=fb016dbf-e310-4920-b9b8-9f0bc04982d5)

You can also use variables within targets and data sources. This allows you to call URLs that will change based on the variable.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FcmEvyN1V3zIzMRyVL8RN%2Fimage.png?alt=media\&token=e1c1a971-e4e2-4ad8-9bbb-62277336c166)

You can also use variables to provide hidden input fields to APIs and scripts.&#x20;

&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FJQG95DgmORoXqXzB32Sx%2Fimage.png?alt=media\&token=3c53db1f-ac28-4e3c-8bc1-b90ab041114c)

## Page Variables

You can load additional data when the page is loading by providing a data source to in the page properties. The data source should return a single PSCustomObject or hashtable. The properties of the object will become variables within the page.&#x20;

For example, assume you have an API that returns the following hashtable.&#x20;

```
@{
    Name = "My Name"
    Title = "My Title"
}
```

Selecting this API as the data source for the page would then create the variables `$Name` and `$Title` within the page.&#x20;

You can also use Route Variables within the data source to customize which API is called based on the route visited.&#x20;

## Route Variables

Route variables need to be defined when creating the URL for the page. Each section of the URL that starts with `:` will be treated as a variable.&#x20;

For example, this page defines a single route variable.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2Fvj9lfKEkk2Ii1gWT9zim%2Fimage.png?alt=media\&token=b47a67ce-9396-4873-9d73-2090d35779c7)

Within the page, the route variables will appear within the variable drawer.&#x20;

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2FHzPuDoC9ZibCO1DdoOiv%2Fimage.png?alt=media\&token=c1c52fea-5612-4d42-abd7-cb6dab55894c)
