Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit cb59ec2

Browse files
committed
Add Helper to get current page
1 parent bf9bbc3 commit cb59ec2

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
using System.Web;
1+
using Our.Umbraco.DocTypeGridEditor.Composing;
2+
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
3+
using System.Web;
24
using System.Web.Mvc;
35
using System.Web.Mvc.Html;
4-
using Our.Umbraco.DocTypeGridEditor.Composing;
5-
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
66
using Umbraco.Core;
77
using Umbraco.Core.Models.PublishedContent;
88

99
namespace Our.Umbraco.DocTypeGridEditor.Web.Extensions
1010
{
1111
public static class HtmlHelperExtensions
1212
{
13+
public static IPublishedContent GetContainerPage(this HtmlHelper helper)
14+
{
15+
//return helper.ViewData["DTGE_ContainerPage"] as IPublishedContent;
16+
if (helper.ViewContext.TempData.ContainsKey("dtgeContainerPage"))
17+
{
18+
return helper.ViewContext.TempData["dtgeContainerPage"] as IPublishedContent;
19+
}
20+
return null;
21+
}
22+
1323
public static HtmlString RenderDocTypeGridEditorItem(
1424
this HtmlHelper helper,
1525
IPublishedElement content,
26+
IPublishedContent containerPage,
1627
string editorAlias = "",
1728
string viewPath = "",
1829
string previewViewPath = "",
@@ -29,6 +40,12 @@ public static HtmlString RenderDocTypeGridEditorItem(
2940
if (string.IsNullOrWhiteSpace(previewViewPath) == false)
3041
previewViewPath = previewViewPath.EnsureEndsWith('/');
3142

43+
//Store the container page reference away for later
44+
if (containerPage != null)
45+
{
46+
helper.ViewContext.TempData["dtgeContainerPage"] = containerPage;
47+
}
48+
3249
var routeValues = new
3350
{
3451
dtgeModel = content,

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
string contentTypeAlias = "";
1212
string value = Model.value.value.ToString();
1313
string viewPath = Model.editor.config.viewPath.ToString();
14-
14+
IPublishedContent containerPage = UmbracoContext.PublishedRequest.PublishedContent;
1515
try
1616
{
1717
contentTypeAlias = Model.value.dtgeContentTypeAlias.ToString();
@@ -25,6 +25,6 @@
2525
{
2626
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, contentTypeAlias, value);
2727

28-
@Html.RenderDocTypeGridEditorItem(content, editorAlias, viewPath)
28+
@Html.RenderDocTypeGridEditorItem(content, containerPage, editorAlias, viewPath)
2929
}
3030
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@using Our.Umbraco.DocTypeGridEditor.Web.Extensions
22
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Our.Umbraco.DocTypeGridEditor.Web.PreviewModel>
3-
@Html.RenderDocTypeGridEditorItem(Model.Item, Model.EditorAlias, Model.ViewPath, Model.PreviewViewPath, true)
3+
@Html.RenderDocTypeGridEditorItem(Model.Item, Model.Page, Model.EditorAlias, Model.ViewPath, Model.PreviewViewPath, true)

0 commit comments

Comments
 (0)