Created
October 26, 2015 20:47
-
-
Save AdamNaj/49a4c59be694f1d314b6 to your computer and use it in GitHub Desktop.
Set item field to external url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-ItemFieldToExternalLink{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] | |
[ValidateNotNullOrEmpty()] | |
[Sitecore.Data.Items.Item]$Item, | |
[Parameter(Position=1, Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$FieldName, | |
[Parameter(Position=2, Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$Url, | |
[Parameter(Position=3)] | |
[string]$Title = "" | |
) | |
$Item.Editing.BeginEdit(); | |
[Sitecore.Data.Fields.LinkField]$field = $Item.Fields[$FieldName] | |
$field.Text = $Title | |
$field.Title = $Title | |
$field.LinkType = "external" | |
$field.Url = $Url | |
$item.Editing.EndEdit() | Out-Null | |
} | |
#Example- assuming the "home" item has a general link field named "GeneralField" | |
Get-Item master:\content\home | Set-ItemFieldToExternalLink -FieldName "GeneralLink" -Url "http://www.cognifide.com" -Title "CognifideWebsite" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment