Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Set-RenderingDatasource {
- [CmdletBinding()]
- param(
- [ValidateNotNullOrEmpty()]
- [Item]$Page,
- [ValidateNotNullOrEmpty()]
- [Item]$Rendering,
- [string]$DatasourceId,
- [string]$Device = "Default",
- [switch]$Publish,
- [string]$PlaceHolder = $null
- )
- $deviceItem = Get-LayoutDevice $Device
- Write-Host "Set rendering datasource on page $($Page.FullPath) on rendering $($Rendering.Name):"
- $renderingInstance = Get-Rendering -Item $Page -Rendering $Rendering -Device $deviceItem -Placeholder $PlaceHolder
- if ($renderingInstance)
- {
- if ($renderingInstance.Datasource -eq $DatasourceId)
- {
- Write-Host "`tDatasource already set on $($Page.FullPath)" -ForegroundColor yellow
- }
- else
- {
- Write-Host "`tUpdating rendering datasource..."
- $renderingInstance.Datasource = $DatasourceId
- Set-Rendering -Item $Page -Instance $renderingInstance
- Write-Host "`tDone" -ForegroundColor green
- if ($Publish -eq $TRUE)
- {
- Write-Host "`tPublishing item..."
- Publish-Item $Page -PublishMode SingleItem
- Write-Host "`tDone" -ForegroundColor green
- }
- }
- }
- else
- {
- Write-Host "ERROR: Couldn't find rendering instance on $($Page.FullPath)" -ForegroundColor red -BackgroundColor white
- }
- }
Add Comment
Please, Sign In to add comment