Added support for reusing the same field in a single snippet file.

This commit is contained in:
Sipke Schoorstra 2015-11-24 23:19:06 +01:00
parent e5bb771be1
commit 37550593d4
2 changed files with 5 additions and 2 deletions

View File

@ -8,7 +8,7 @@ using Orchard.Localization;
namespace Orchard.Layouts.Helpers {
public static class SnippetHtmlExtensions {
public static SnippetFieldDescriptorBuilder SnippetField(this HtmlHelper htmlHelper, string name, string type) {
public static SnippetFieldDescriptorBuilder SnippetField(this HtmlHelper htmlHelper, string name, string type = null) {
var shape = (dynamic) htmlHelper.ViewData.Model;
return new SnippetFieldDescriptorBuilder(shape)

View File

@ -141,7 +141,10 @@ namespace Orchard.Layouts.Providers {
// Execute the shape and intercept calls to the Html.SnippetField method.
var descriptor = new SnippetDescriptor();
shape.DescriptorRegistrationCallback = (Action<SnippetFieldDescriptor>) (fieldDescriptor => {
descriptor.Fields.Add(fieldDescriptor);
var existingDescriptor = descriptor.Fields.SingleOrDefault(x => x.Name == fieldDescriptor.Name); // Not using Dictionary, as that will break rendering the view for some obscure reason.
if (existingDescriptor == null)
descriptor.Fields.Add(fieldDescriptor);
if (fieldDescriptor.DisplayName == null)
fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);