Move block grid single area rendering to its own dedicated view (#13359)

This commit is contained in:
Kenn Jacobsen
2022-11-08 13:34:12 +01:00
committed by GitHub
parent 2a952c7374
commit b5842d6a7d
7 changed files with 81 additions and 16 deletions

View File

@@ -14,6 +14,7 @@ public static class BlockGridTemplateExtensions
public const string DefaultTemplate = "default";
public const string DefaultItemsTemplate = "items";
public const string DefaultItemAreasTemplate = "areas";
public const string DefaultItemAreaTemplate = "area";
#region Async
@@ -60,6 +61,20 @@ public static class BlockGridTemplateExtensions
public static async Task<IHtmlContent> GetBlockGridItemAreasHtmlAsync(this IHtmlHelper html, BlockGridItem item, string template = DefaultItemAreasTemplate)
=> await html.PartialAsync(DefaultFolderTemplate(template), item);
public static async Task<IHtmlContent> GetBlockGridItemAreaHtmlAsync(this IHtmlHelper html, BlockGridArea area, string template = DefaultItemAreaTemplate)
=> await html.PartialAsync(DefaultFolderTemplate(template), area);
public static async Task<IHtmlContent> GetBlockGridItemAreaHtmlAsync(this IHtmlHelper html, BlockGridItem item, string areaAlias, string template = DefaultItemAreaTemplate)
{
BlockGridArea? area = item.Areas.FirstOrDefault(a => a.Alias == areaAlias);
if (area == null)
{
return new HtmlString(string.Empty);
}
return await GetBlockGridItemAreaHtmlAsync(html, area, template);
}
#endregion
#region Sync
@@ -95,6 +110,17 @@ public static class BlockGridTemplateExtensions
public static IHtmlContent GetBlockGridItemAreasHtml(this IHtmlHelper html, BlockGridItem item, string template = DefaultItemAreasTemplate)
=> html.Partial(DefaultFolderTemplate(template), item);
public static IHtmlContent GetBlockGridItemAreaHtml(this IHtmlHelper html, BlockGridArea area, string template = DefaultItemAreaTemplate)
=> html.Partial(DefaultFolderTemplate(template), area);
public static IHtmlContent GetBlockGridItemAreaHtml(this IHtmlHelper html, BlockGridItem item, string areaAlias, string template = DefaultItemAreaTemplate)
{
BlockGridArea? area = item.Areas.FirstOrDefault(a => a.Alias == areaAlias);
return area != null
? GetBlockGridItemAreaHtml(html, area, template)
: new HtmlString(string.Empty);
}
#endregion
private static string DefaultFolderTemplate(string template) => $"{DefaultFolder}{template}";