# Variables

{% hint style="info" %}
This feature requires a [PowerShell Universal license](https://docs.powershelluniversal.com/master-1/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://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2F1XEc3177I7G8EC0U8rxv%2Fimage.png?alt=media\&token=3f322a4e-9818-4c77-8273-ee2d3c93e0dd)

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

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FvFB27g5lUxgTla2aERap%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://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FLmT7YK3GEviakq2qE7O8%2Fimage.png?alt=media\&token=331644a8-a2ad-46b6-b5ee-c446b04f05fb)

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

![](https://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FHFXlnYfwKx5juCdWww7P%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://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FSO0Lw3wWS8ux1vSXG3RS%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://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2Fwe0PkjVd3h0i8fEULlUo%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://3638551245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6jY7sXTmhiAIMGYw_m-887967055%2Fuploads%2FRyupQivlWWzrCz99x2hJ%2Fimage.png?alt=media\&token=b47a67ce-9396-4873-9d73-2090d35779c7)

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

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