1

I have a script which loops over different sites in a Sitecore instance. For each site some tasks are done, such as creating and moving items. How can I set the language context for these operations based on the language set in the config for the current site (if this is not feasible, I would settle for using the language of the current item).

$sites = Get-Item master: -Query "fast:/sitecore/content/Master//*[@@templatename='Website']";
foreach ($site in $sites) {
    #determine the correct language of the $site item based off the sites configuration setting
}

1 Answer 1

3

If all of your sites point to different items, here's what you can do:

$sitePath = $site.Paths.FullPath.Trim().ToLower()

$siteInfo =
    [Sitecore.Configuration.Factory]::GetSiteInfoList() |
        ? { ($_.RootPath.Length -gt 0) -and $sitePath -eq ($_.RootPath + $_.StartItem).ToLower() } |
        select -first 1

if($siteInfo -ne $null) {
    $language = $siteInfo.Language
    # ...
}

If your $site items can have multiple site definitions bound to them, then you have to use the language of the item:

$language = $site.Language.Name

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.