我希望能够在Sitecore中存储可重用的html格式文本,并在codebehind中引用以包含在自定义用户控件中。这样做的最佳做法是什么?例如,如果用户选择选项A,我将在我的控件中引用标准文本A.任何关于如何实现这一点的例子都表示赞赏。感谢。
答案 0 :(得分:2)
您有几个选择:
No.2:
//get the item where we have the text values
Item textBase = Sitecore.Context.Database.SelectSingleItem(textBasePath);
//find the child w/ the same name as the selected option
Item textItem = textBase.Axes.GetChild(selectedOptionValue);
string value = textItem["text"];
答案 1 :(得分:0)
我想我会做类似techphoria414的2.选项:
即你按照惯例拥有正常的“页面”模板,但是你有一些字段(多列表,树状列表字段),其中你指向其他项目的源包含不同的文本。
然后你基本上只需要从当前项目中获取项目(使用一些非常快速的代码/伪代码):
var CurrentItem = Sitecore.Context.Item;
Sitecore.Data.Fields.MultilistField mlf1 = CurrentItem.Fields["myExternalTexts"];
if(mlf1 != null)
{
foreach (Item itm in mlf1.GetItems())
{
lit += Sitecore.Web.UI.WebControls.FieldRenderer.Render(itm, "richtext");
}
}
你不应该只是将它们添加到文字中,如果使用Sitecore 6或更高版本并且它是富文本字段,那么你应该在Site renderes中构建Sitecore。
我希望有所帮助。