3

My goal is to use the Show-ListView function available in Sitecore Powershell to show a dynamic number of columns. I'm currently executing the Show-ListView function as follows:

$table |
    Show-ListView @props -Property @{ Label = "Item"; Expression = { $_.Item} },
    @{ Label = "Page Type"; Expression = { $_.PageType } },
    @{ Label = "Path"; Expression = { $_.Path} },
    @{ Label = "en"; Expression = { $_.'en' } },
    @{ Label = "en-AU"; Expression = { $_.'en-au' } },
    @{ Label = "en-CA"; Expression = { $_.'en-ca' } },
    @{ Label = "en-GB"; Expression = { $_.'en-gb' } },
    @{ Label = "en-IN"; Expression = { $_.'en-in' } },
    @{ Label = "en-SG"; Expression = { $_.'en-sg' } },
    @{ Label = "fr-CA"; Expression = { $_.'fr-ca' } },
    @{ Label = "ja-JP"; Expression = { $_.'ja-jp' } },
    @{ Label = "zh-CN"; Expression = { $_.'zh-cn' } }

I'd like for the list of languages printed to be dynamic based on input I'm gathering from the user. I've already successfully read in the user input using the Read-Variable function but I'm not sure if there is a way to use this list to dynamically generate columns.

Is this possible using the built-in Sitecore Powershell functions or does the column generation have to be exclusively static?

1 Answer 1

6

Yes it is possible to dynamically render the fields in the Show-ListView. You can read more from the article I posted: Sitecore Powershell Dynamic UI.

Based on your current requirement, I have assumed that the Read-Variables takes as input a list of language. Below is a code snippet that split the languages and then create a pattern.

$result = Read-Variable -Parameters `
    @{ Name = "inputLanguages"; Value=""; Title="Text"; Tab="Language"; Placeholder="Input Languages delimited by ,"} `
    -Description "Language Options" `
    -Title "SSE Question" -Width 650 -Height 700 -OkButtonName "Proceed" -CancelButtonName "Abort" -ShowHints

if($result -ne "ok")
{
    Exit
}

$pattern = ""

$languages = $inputLanguages -split ","
$counter = 1

foreach($language in $languages){

    if($languages.length -eq $counter){
        $pattern += '@{ Label = "'+$language+'"; Expression = { $_."'+$language.ToLower()+'" }; }'
    }
    else{
        $pattern += '@{ Label = "'+$language+'"; Expression = { $_."'+$language.ToLower()+'" }; },'
    }

    $counter++
}

$convertPattern = Invoke-Expression $pattern


Get-ChildItem -Path "master:\sitecore\content\Home" | Show-ListView -Property $convertPattern 

The outcome is shown in the screenshot below

enter image description here

1
  • This is exactly what I was looking for! Thank you!
    – c-bro
    Commented Sep 24, 2018 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.