可通过页面编辑器编辑的Sitecore词典项
我正在尝试通过PageEditor实现要编辑的Sitecore字典项 这是我的方法。。只需要你的想法和建议 为了简单起见,不要弄乱管道,这里有一个我正在做的简单方法 通常,您会进行sitecore翻译,例如 @Sitecore.Globalization.Translate.Text(“SomeKey”) 您可以将Translate封装为一个自定义类,该类可能如下所示可通过页面编辑器编辑的Sitecore词典项,sitecore,Sitecore,我正在尝试通过PageEditor实现要编辑的Sitecore字典项 这是我的方法。。只需要你的想法和建议 为了简单起见,不要弄乱管道,这里有一个我正在做的简单方法 通常,您会进行sitecore翻译,例如 @Sitecore.Globalization.Translate.Text(“SomeKey”) 您可以将Translate封装为一个自定义类,该类可能如下所示 public static class CustomTranslate { public static string Te
public static class CustomTranslate
{
public static string Text(string key)
{
if (Sitecore.Context.PageMode.IsPageEditorEditing)
{
string val = String.Empty;
Item currentItem = Context.Database.GetItem(ResourcesController.ItemLookUp()[key]);
if (currentItem != null)
{
val = FieldRenderer.Render(currentItem, "Phrase");
}
return val;
}
else
return Sitecore.Globalization.Translate.Text(key);
}
}
CustomTranslate.Text以页面编辑模式返回FieldRenderer,否则返回Sitecore.Globalization.Translate.Text
然后在代码中,您可以将这些翻译引用为
@CustomTranslate.Text(“SomeKey”)
查找可以是键和项ID的字典,如下面的代码所示
public static class ResourceController
{
public static Dictionary ItemLookUp()
{
///get dictionary path..etc.. code not included
//read all sitecore dictionary Items
Sitecore.Data.Items.Item[] items =
Sitecore.Context.Database.SelectItems("fast:" + dictionaryPath +
"//*[@@templateid='{6D1CD897-1936-4A3A-A511-289A94C2A7B1}']");
//build a Dictionary<string,string> using sitecore item key and Guid.
items.All(y => { resourceDictionary.Add(y["Key"], y.ID.Guid.ToString()); return true;}
// Key,Guid dictionary
return resourceDictionary;
}
}
公共静态类ResourceController
{
公共静态字典ItemLookUp()
{
///获取字典路径..等..未包含代码
//读取所有sitecore字典项
Sitecore.Data.Items.Item[]项目=
Sitecore.Context.Database.SelectItems(“fast:+dictionaryPath+
“//*[@@templateid='{6D1CD897-1936-4A3A-A511-289A94C2A7B1}'”;
//使用sitecore项键和Guid构建字典。
items.All(y=>{resourceDictionary.Add(y[“Key”],y.ID.Guid.ToString());返回true;}
//键,Guid字典
返回资源字典;
}
}
一个更简单、更容易的方法!想法、评论?今天刚刚看到这篇文章-。这可能会有所帮助。谢谢。看到这篇文章..需要相当长的时间和测试。