Sitecore规则未将数据源设置为其他项?
这是我的规矩 其中用户配置文件fb_likes字段包含sitecore 将数据源设置为TestItem2 我已将此规则应用于模板标准值的子布局,但此规则从未更改数据源 我也试过这种情况 其中为true(操作始终执行) 但同样没有运气 如果我将操作更改为 隐藏渲染 它很好用。Sitecore规则未将数据源设置为其他项?,sitecore,sitecore6,Sitecore,Sitecore6,这是我的规矩 其中用户配置文件fb_likes字段包含sitecore 将数据源设置为TestItem2 我已将此规则应用于模板标准值的子布局,但此规则从未更改数据源 我也试过这种情况 其中为true(操作始终执行) 但同样没有运气 如果我将操作更改为 隐藏渲染 它很好用。 这里我做错了什么???当数据源设置在上下文项上时,子布局的代码是否允许使用该数据源?您可以通过多种方式实现这一点。例如,在基类中: protected string DataSource {
这里我做错了什么???当数据源设置在上下文项上时,子布局的代码是否允许使用该数据源?您可以通过多种方式实现这一点。例如,在基类中:
protected string DataSource
{
get
{
var sublayout = Parent as SublayoutBase;
return sublayout == null ? string.Empty : sublayout.DataSource;
}
}
protected Item DataSourceItem
{
get
{
return string.IsNullOrEmpty(DataSource)
? Sitecore.Context.Item
: Sitecore.Context.Database.GetItem(DataSource) ?? Sitecore.Context.Item;
}
}
然后在子布局的代码中使用DatSourceItem而不是上下文项来显示内容。我看到的另一种方法是:
protected override void Render(HtmlTextWriter writer)
{
if (this.DataSourceItem != null)
using (new Sitecore.Data.Items.ContextItemSwitcher(this.DataSourceItem ))
{
base.Render(writer);
}
else
{
base.Render(writer);
}
}
使用此选项,即使代码是针对上下文项编写的,在基类中继承此选项的所有子布局都将在本机上支持数据源。子布局的代码是否允许在对上下文项进行设置时使用数据源?您可以通过多种方式实现这一点。例如,在基类中:
protected string DataSource
{
get
{
var sublayout = Parent as SublayoutBase;
return sublayout == null ? string.Empty : sublayout.DataSource;
}
}
protected Item DataSourceItem
{
get
{
return string.IsNullOrEmpty(DataSource)
? Sitecore.Context.Item
: Sitecore.Context.Database.GetItem(DataSource) ?? Sitecore.Context.Item;
}
}
然后在子布局的代码中使用DatSourceItem而不是上下文项来显示内容。我看到的另一种方法是:
protected override void Render(HtmlTextWriter writer)
{
if (this.DataSourceItem != null)
using (new Sitecore.Data.Items.ContextItemSwitcher(this.DataSourceItem ))
{
base.Render(writer);
}
else
{
base.Render(writer);
}
}
使用此选项,即使代码是针对上下文项编写的,在基类中继承此选项的所有子布局都将在本机上支持数据源