# Dynamic

The dynamic component allows you to run PowerShell script to generate PSBlazor components on the fly. It's context aware.

{% hint style="warning" %}
Because dynamic components run PowerShell with each render, they can reduce the performance of your apps.
{% endhint %}

A dynamic component is defined with a function that will be executed when the app is loaded.

```xml
<Dynamic Function="RenderMyDynamic" />
```

Within the dynamic, return a string that will be rendered. It must be valid PSBlazor syntax.

```powershell
function RenderMyDynamic {
    "<Alert Message='Cool!' />"
}
```

If you are using a dynamic within a component that sets a context variable, you can use the context in your function. In this example, we have a table of services that uses a dynamic in the status column.

```markup
<Table DataSource="$Services">
    <PropertyColumn Property="Name" />
    <PropertyColumn Property="Status">
        <Dynamic Function="RenderStatusColumn" />
    </PropertyColumn>
</Table>
```

The function `RenderStatusColumn` will be called for each row in the table.

```powershell
function RenderStatusColumn {
    param($Context)
    
    if ($Context.Status -eq 'Running')
    {
        "<Alert Message='Started' />"
    }
    else 
    {
        "<Alert Message='$($Context.Status)' />"
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/portal/portal-widgets/dynamic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
