From f22d3cdef3c8ea549044bd3d27860339c050eb8c Mon Sep 17 00:00:00 2001 From: Jamie Gilbert Date: Fri, 5 Feb 2016 14:33:02 +0000 Subject: [PATCH 1/3] Modified HTML helper to allow you to render a single fieldset from an Archtype model. (I Needed to render the first review in a list of review blocks) --- .../Extensions/HtmlHelperExtensions.cs | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs b/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs index 7606b6a..ee47164 100644 --- a/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs +++ b/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs @@ -12,6 +12,56 @@ namespace Archetype.Extensions /// public static class HtmlHelperExtensions { + /// + /// Renders a single archtype partial from a fieldset + /// + /// The HTML helper. + /// The fieldset model. + /// + public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel) + { + return RenderPartial(htmlHelper, fieldsetModel, null, null); + } + + /// + /// Renders the fieldset partial + /// + /// The HTML helper. + /// + /// The partial path. + /// The view data dictionary. + /// + private static IHtmlString RenderPartial(HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialPath, ViewDataDictionary viewDataDictionary) + { + var context = HttpContext.Current; + + if (fieldsetModel == null || context == null) + { + return new HtmlString(""); + } + + var sb = new StringBuilder(); + + var pathToPartials = "~/Views/Partials/Archetype/"; + if (!string.IsNullOrEmpty(partialPath)) + { + pathToPartials = partialPath; + } + + var partial = pathToPartials + fieldsetModel.Alias + ".cshtml"; + + if (System.IO.File.Exists(context.Server.MapPath(partial))) + { + sb.AppendLine(htmlHelper.Partial(partial, fieldsetModel, viewDataDictionary).ToString()); + } + else + { + LogHelper.Info(string.Format("The partial for {0} could not be found. Please create a partial with that name or rename your alias.", context.Server.MapPath(partial))); + } + + return new HtmlString(sb.ToString()); + } + /// /// Renders the archetype partials. /// @@ -72,31 +122,11 @@ namespace Archetype.Extensions { var context = HttpContext.Current; - if (archetypeModel == null || context == null) - { - return new HtmlString(""); - } - var sb = new StringBuilder(); - var pathToPartials = "~/Views/Partials/Archetype/"; - if (!string.IsNullOrEmpty(partialPath)) - { - pathToPartials = partialPath; - } - foreach (var fieldsetModel in archetypeModel) { - var partial = pathToPartials + fieldsetModel.Alias + ".cshtml"; - - if (System.IO.File.Exists(context.Server.MapPath(partial))) - { - sb.AppendLine(htmlHelper.Partial(partial, fieldsetModel, viewDataDictionary).ToString()); - } - else - { - LogHelper.Info(string.Format("The partial for {0} could not be found. Please create a partial with that name or rename your alias.", context.Server.MapPath(partial))); - } + sb.AppendLine(RenderPartial(htmlHelper, fieldsetModel, partialPath, viewDataDictionary).ToString()); } return new HtmlString(sb.ToString()); From d63f7a6a341e59c485377077ec24c5ad13880e82 Mon Sep 17 00:00:00 2001 From: Jamie Gilbert Date: Wed, 24 Feb 2016 17:00:32 +0000 Subject: [PATCH 2/3] updated angular controller to find view when umbraco is in virtual directory (using relative path) --- app/directives/archetypecustomview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/directives/archetypecustomview.js b/app/directives/archetypecustomview.js index d6719aa..3cc83c5 100644 --- a/app/directives/archetypecustomview.js +++ b/app/directives/archetypecustomview.js @@ -1,7 +1,7 @@ angular.module("umbraco.directives").directive('archetypeCustomView', function ($compile, $http) { var linker = function (scope, element, attrs) { - var view = "/App_plugins/Archetype/views/archetype.default.html"; + var view = "../App_plugins/Archetype/views/archetype.default.html"; if(scope.model.config.customViewPath) { view = scope.model.config.customViewPath; } From e0613116896dc6c79510b705e69d8ef1d2d4ddf7 Mon Sep 17 00:00:00 2001 From: kgiszewski Date: Thu, 10 Mar 2016 11:16:27 -0500 Subject: [PATCH 3/3] Add overloads for single partial render and cleanup stuffs --- .../Extensions/HtmlHelperExtensions.cs | 89 ++++++++++++------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs b/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs index ee47164..204fb80 100644 --- a/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs +++ b/app/Umbraco/Umbraco.Archetype/Extensions/HtmlHelperExtensions.cs @@ -13,14 +13,23 @@ namespace Archetype.Extensions public static class HtmlHelperExtensions { /// - /// Renders a single archtype partial from a fieldset + /// Renders the partials based on the model, partial path and given viewdata dictionary. /// /// The HTML helper. - /// The fieldset model. + /// The archetype model. + /// The partial path. + /// The view data dictionary. /// - public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel) + private static IHtmlString _renderPartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath, ViewDataDictionary viewDataDictionary) { - return RenderPartial(htmlHelper, fieldsetModel, null, null); + var sb = new StringBuilder(); + + foreach (var fieldsetModel in archetypeModel) + { + sb.AppendLine(_renderPartial(htmlHelper, fieldsetModel, partialPath, viewDataDictionary).ToString()); + } + + return new HtmlString(sb.ToString()); } /// @@ -31,7 +40,7 @@ namespace Archetype.Extensions /// The partial path. /// The view data dictionary. /// - private static IHtmlString RenderPartial(HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialPath, ViewDataDictionary viewDataDictionary) + private static IHtmlString _renderPartial(HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialPath, ViewDataDictionary viewDataDictionary) { var context = HttpContext.Current; @@ -42,13 +51,15 @@ namespace Archetype.Extensions var sb = new StringBuilder(); + //default var pathToPartials = "~/Views/Partials/Archetype/"; + if (!string.IsNullOrEmpty(partialPath)) { pathToPartials = partialPath; } - var partial = pathToPartials + fieldsetModel.Alias + ".cshtml"; + var partial = string.Format("{0}{1}.cshtml", pathToPartials, fieldsetModel.Alias); if (System.IO.File.Exists(context.Server.MapPath(partial))) { @@ -62,6 +73,42 @@ namespace Archetype.Extensions return new HtmlString(sb.ToString()); } + /// + /// Renders a single archtype partial from a fieldset + /// + /// The HTML helper. + /// The fieldset model. + /// + public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel) + { + return _renderPartial(htmlHelper, fieldsetModel, null, null); + } + + /// + /// Renders the archetype partial. + /// + /// The HTML helper. + /// The fieldset model. + /// The partial view. + /// + public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView) + { + return _renderPartial(htmlHelper, fieldsetModel, partialView, null); + } + + /// + /// Renders the archetype partial. + /// + /// The HTML helper. + /// The fieldset model. + /// The partial view. + /// The view data dictionary. + /// + public static IHtmlString RenderArchetypePartial(this HtmlHelper htmlHelper, ArchetypeFieldsetModel fieldsetModel, string partialView, ViewDataDictionary viewDataDictionary) + { + return _renderPartial(htmlHelper, fieldsetModel, partialView, viewDataDictionary); + } + /// /// Renders the archetype partials. /// @@ -70,7 +117,7 @@ namespace Archetype.Extensions /// public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel) { - return RenderPartials(htmlHelper, archetypeModel, null, null); + return _renderPartials(htmlHelper, archetypeModel, null, null); } /// @@ -82,7 +129,7 @@ namespace Archetype.Extensions /// public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath) { - return RenderPartials(htmlHelper, archetypeModel, partialPath, null); + return _renderPartials(htmlHelper, archetypeModel, partialPath, null); } /// @@ -94,7 +141,7 @@ namespace Archetype.Extensions /// public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, ViewDataDictionary viewDataDictionary) { - return RenderPartials(htmlHelper, archetypeModel, null, viewDataDictionary); + return _renderPartials(htmlHelper, archetypeModel, null, viewDataDictionary); } /// @@ -107,29 +154,7 @@ namespace Archetype.Extensions /// public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath, ViewDataDictionary viewDataDictionary) { - return htmlHelper.RenderPartials(archetypeModel, partialPath, viewDataDictionary); - } - - /// - /// Renders the partials based on the model, partial path and given viewdata dictionary. - /// - /// The HTML helper. - /// The archetype model. - /// The partial path. - /// The view data dictionary. - /// - private static IHtmlString RenderPartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath, ViewDataDictionary viewDataDictionary) - { - var context = HttpContext.Current; - - var sb = new StringBuilder(); - - foreach (var fieldsetModel in archetypeModel) - { - sb.AppendLine(RenderPartial(htmlHelper, fieldsetModel, partialPath, viewDataDictionary).ToString()); - } - - return new HtmlString(sb.ToString()); + return htmlHelper._renderPartials(archetypeModel, partialPath, viewDataDictionary); } } } \ No newline at end of file