2017-08-24 18 views
0

是否有任何方法可以一次在Sitecore中爲最終用戶創建所有頁面的所有頁面標題?可能通過數據庫或由Sitecore提供的任何設置?在SiteCore中創建的所有頁面中更改頁面標題

編輯:

  • 我在Sitecore的管理創造了超過500頁。

  • 每個頁面都有一個字段(我稱爲頁面標題),它顯示爲一個HTML頁面標題,它是<title><.title>

  • 現在我有要求將所有頁面中的標題更改爲其他內容。

  • 我需要有更快的方法來一次更改所有內容,而不是打開每個頁面,更改標題,保存併發布它。

+0

我建議煉你的問題。你想對頁面標題做什麼?你想更新它們在開始/結束時添加一個特定的單詞嗎?我無法想象你想讓所有頁面擁有相同的頁面標題。但答案可能是一些使用Sitecore Powershell Extensions(SPE)的腳本。 –

+0

我正在投票結束這個問題,因爲它涉及到最終用戶功能,因此不是特定的編程/編程工具--OP要求提供沒有編程元素的解決方案。 –

回答

0

最快的方法是使用Sitecore Powershell模塊來設置所有項目的值。喜歡的東西:

cd 'master:/sitecore/content' 
Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match "{template name}" -and $_.Fields["Title"] -ne $null } | ForEach-Object { 
    $_.Editing.BeginEdit() 
    $_.Fields["Title"].Value = "{new value}"; 
    $_.Editing.EndEdit() 
    "" 
} 

如果你不想使用Sitecore的PowerShell中,你可以使用C#編寫,通過樹循環遞歸函數。

例子:

private void UpdateAllFieldsRecursively(Item parentItem, string templateName, string fieldName, string newValue) 
{ 
    if (parentItem != null) 
    { 
     using (new SecurityDisabler()) 
     { 
      foreach (Item childItem in parentItem.Children) 
      { 
       if (childItem.Fields[fieldName] != null && childItem.TemplateName == templateName) 
       { 
        using (new EditContext(childItem)) 
        { 
         childItem[fieldName] = newValue; 
        } 
       } 
       if (childItem.HasChildren) 
       { 
        UpdateAllFieldsRecursively(childItem, templateName, fieldName, newValue); 
       } 
      } 
     } 
    } 
} 

在那裏你可以調用函數像這樣:

const string parentNode = "/sitecore/content"; 
var database = Sitecore.Context.Database; 
var parentItem = database.GetItem(parentNode); 

UpdateAllFieldsRecursively(parentItem, "{template name}", "Title", "{new value}"); 
相關問題