Posts

Showing posts from February, 2021

Sitecore powershell copy from one General Link field to another

 We have requirement to copy from one general link url to another field. $allitems=Get-ChildItem -Path 'master://sitecore/content/Global -Recurse | Where-Object { $_.TemplateName -eq "Relatedcontent" }   $allitems | ForEach-Object {             [Sitecore.Data.Fields.LinkField]$field = $_.Fields["Navigation Link"]         [Sitecore.Data.Fields.LinkField]$fieldnew = $_.Fields["Navigation Link1"]         $_.Editing.BeginEdit()                        $fieldnew.LinkType=  $field.LinkType          $fieldnew.TargetID=$field.TargetID         $fieldnew.Url =$field.Url         $_.Fields["NavigationTitle1"].Value=$_.Fields["NavigationTitle"].Value         $_.Editing.EndEdit() | Out-Null              Write-Host $_.FullPath }

Sitecore scriban for language dropdown

 We using scriban template to load language selector for the website , as not using out of box SXA language selector, we need more control from content author side. We have template with language multilist field , so that the content author have control to select or deselect the languages as per their wish. Scriban template to load language selector: Loop through all the languages content author selected from the field " Site Languages " and compare with the context language to make it as active language Url will be dynamic based on the language   <ul>        {{ for languages in (sc_followmany i_datasource "Site Languages"  )  }}              {{ itemLanguage=(sc_field  languages 'Regional Iso Code') }}              {{itemLanguage=(itemLanguage | string.downcase)}}              {{contextLanguage=(i_datasource.language )| string.downcase}}                   {{if contextLanguage== itemLanguage }}                     <li class="{{sc_fie

Sitecore SXA updating NameValueList in (Rendering variant Data Attributes) using powershell and programmatically

 We have requirement to bulk update VariantSection template "Data Attribute" field's one property "alt" or "data-alt" with some custom value. I have given solution using powershell and C# Powershell way   $items = Get-ChildItem -Path "master:\sitecore\content\Shared\Presentation\Rendering Variants" -Recurse | Where-Object { $_.TemplateId -eq "{ACA5C9A3-CDA0-49B6-893F-1D4A7CB595B0}" } foreach($item in $items)  {     $isAlt=$false     $nameValues = [System.Web.HttpUtility]::ParseQueryString($item.Fields["DataAttributes"])     Write-Host $nameValues     foreach($key in $nameValues.AllKeys)      {         if ($key -eq "alt" -Or $key -eq "data-alt")         {             $isAlt=$true             $nameValues[$key] = "sample value"             Write-Host $key= $nameValues[$key]         }     }     if($isAlt)     {         $item.Editing.BeginEdit()        $item.Fields["DataAttributes"].Value

Sitecore Powershell for Bulk update General Link "External" field

We have a general link field which pointing to different site url , but the domain name of that site changes due to some reason, so it makes us to update our general link field url, we have references in lot of place  , so i tried to use the below scripts to update the domain name $allItems = Get-ChildItem -Path 'master://sitecore/content/ Tenant/Corporate/Global' -Recurse   $allItems | ForEach-Object {     [Sitecore.Data.Fields.LinkField]$field = $_.Fields["Navigation Link"]     if($field.LinkType -eq "external")     {         $Url = $field.Url         $_.Editing.BeginEdit()                         $field.LinkType = "external"         $field.Url =                     $Url.Replace('www.xxxx.com/news/','www.yyyyyy.com/news/')         $_.Editing.EndEdit() | Out-Null               Write-Host $_.FullPath         Write-Host  $Url.Replace('www.dpworld.com/news/','www.dpworld.com/news/releases/')     } }