我正在按照文章中的描述,在Sitecore 7中实现动态占位符。
我期望的是会提示我可以放置在动态占位符上的允许渲染。相反,呈现了渲染/布局树以手动选择渲染 - 使内容编辑人员能够向占位符添加不允许的渲染。
我已经调试了代码,并找到了动态占位符的正确占位符设置项,也已检索到允许的渲染列表,但尽管在args中进行了设置,该列表并未呈现给用户。请参见下面的代码。
由于这段代码是为Sitecore 6.5 / 6.6开发的,我想知道升级到Sitecore 7.0是否会影响代码后半部分。
- http://trueclarity.wordpress.com/2012/06/19/dynamic-placeholder-keys-in-sitecore/
- http://www.techphoria414.com/Blog/2011/August/Dynamic_Placeholder_Keys_Prototype
我期望的是会提示我可以放置在动态占位符上的允许渲染。相反,呈现了渲染/布局树以手动选择渲染 - 使内容编辑人员能够向占位符添加不允许的渲染。
我已经调试了代码,并找到了动态占位符的正确占位符设置项,也已检索到允许的渲染列表,但尽管在args中进行了设置,该列表并未呈现给用户。请参见下面的代码。
public class GetDynamicKeyAllowedRenderings : GetAllowedRenderings
{
//string that ends in a GUID
public const string DynamicKeyRegex = @"(.+){[\d\w]{8}\-([\d\w]{4}\-){3}[\d\w]{12}}";
public new void Process(GetPlaceholderRenderingsArgs args)
{
Assert.IsNotNull(args, "args");
// get the placeholder key
string placeholderKey = args.PlaceholderKey;
var regex = new Regex(DynamicKeyRegex);
Match match = regex.Match(placeholderKey);
// if the placeholder key text followed by a Guid
if (match.Success && match.Groups.Count > 0)
{
// Is a dynamic placeholder
placeholderKey = match.Groups[1].Value;
}
else
{
return;
}
Item placeholderItem = null;
if (ID.IsNullOrEmpty(args.DeviceId))
{
placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase,
args.LayoutDefinition);
}
else
{
using (new DeviceSwitcher(args.DeviceId, args.ContentDatabase))
{
placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase,
args.LayoutDefinition);
}
}
// Retrieve the allowed renderings for the Placeholder
List<Item> collection = null;
if (placeholderItem != null)
{
bool allowedControlsSpecified;
args.HasPlaceholderSettings = true;
collection = this.GetRenderings(placeholderItem, out allowedControlsSpecified);
if (allowedControlsSpecified)
{
args.CustomData["allowedControlsSpecified"] = true;
}
}
if (collection != null)
{
if (args.PlaceholderRenderings == null)
{
args.PlaceholderRenderings = new List<Item>();
}
args.PlaceholderRenderings.AddRange(collection);
}
}
}
由于这段代码是为Sitecore 6.5 / 6.6开发的,我想知道升级到Sitecore 7.0是否会影响代码后半部分。