4
我实现动态占位符在Sitecore的7中的文章Sitecore的动态占位符允许效果图
- 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带来了影响代码的后半段的变化
嘿..尼克乔纳森。是否可以选择第一个允许的渲染并将其应用于占位符而不弹出“选择渲染”对话框? – 2015-10-14 12:43:56
这是一个很好的问题。这应该是可能的,但它可能需要大量的工作。本质上,我设置args.Options.ShowTree = false;你需要打电话给允许的渲染。然后反编译Sitecore代码以查找Select a Rendering的按钮点击并在允许的渲染调用之后复制它。 – 2015-10-14 13:15:18
正是我正在寻找....这意味着我将不得不扩展sitecore的应用渲染的实现。任何领先的地方我可以找到该代码。? – 2015-10-14 13:19:26