Guest User

Untitled

a guest
Jul 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. function Set-RenderingDatasource {
  2. [CmdletBinding()]
  3. param(
  4. [ValidateNotNullOrEmpty()]
  5. [Item]$Page,
  6.  
  7. [ValidateNotNullOrEmpty()]
  8. [Item]$Rendering,
  9.  
  10. [string]$DatasourceId,
  11.  
  12. [string]$Device = "Default",
  13.  
  14. [switch]$Publish,
  15.  
  16. [string]$PlaceHolder = $null
  17. )
  18.  
  19. $deviceItem = Get-LayoutDevice $Device
  20.  
  21. Write-Host "Set rendering datasource on page $($Page.FullPath) on rendering $($Rendering.Name):"
  22.  
  23. $renderingInstance = Get-Rendering -Item $Page -Rendering $Rendering -Device $deviceItem -Placeholder $PlaceHolder
  24.  
  25. if ($renderingInstance)
  26. {
  27. if ($renderingInstance.Datasource -eq $DatasourceId)
  28. {
  29. Write-Host "`tDatasource already set on $($Page.FullPath)" -ForegroundColor yellow
  30. }
  31. else
  32. {
  33. Write-Host "`tUpdating rendering datasource..."
  34.  
  35. $renderingInstance.Datasource = $DatasourceId
  36. Set-Rendering -Item $Page -Instance $renderingInstance
  37. Write-Host "`tDone" -ForegroundColor green
  38.  
  39. if ($Publish -eq $TRUE)
  40. {
  41. Write-Host "`tPublishing item..."
  42. Publish-Item $Page -PublishMode SingleItem
  43. Write-Host "`tDone" -ForegroundColor green
  44. }
  45. }
  46. }
  47. else
  48. {
  49. Write-Host "ERROR: Couldn't find rendering instance on $($Page.FullPath)" -ForegroundColor red -BackgroundColor white
  50. }
  51. }
Add Comment
Please, Sign In to add comment