Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.38 KB

dynamic.md

File metadata and controls

53 lines (41 loc) · 1.38 KB
description
Dynamic component for portal components.

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.

<Dynamic Function="RenderMyDynamic" />

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

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.

<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.

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