AI OnAI Off
Any help from these?
https://stackoverflow.com/questions/26909831/access-current-page-from-a-blocks-controller
Not tested but something like this
Injected<IPageRouteHelper> pageRouteHelper;
if (pageRouteHelper.Page is BasePageData currentPage)
{
var property = currentPage.Property
}
So do you want to use the properties of the current page(not sure about parent page) on the block?
Hi Ričardas,
You can try this extension method to retrieve the Ancestor and Self-content.
public static IEnumerable<IContent> GetAncestorsAndSelf(this IContentLoader contentLoader, IContent content, bool includeEntries = false)
{
if (contentLoader == null || content == null)
return Enumerable.Empty<IContent>();
var ancestorsAndSelf = contentLoader.GetAncestors(content.ContentLink)?.Reverse().ToList() ?? new List<IContent>();
if (includeEntries && content is IContent entry)
{
var ancestorEntriesAndSelf = contentLoader.GetAncestorEntriesAndSelf(entry);
ancestorsAndSelf.AddRange(ancestorEntriesAndSelf);
}
else
{
ancestorsAndSelf.Add(content);
}
return ancestorsAndSelf;
}
Hey all,
is there a quick and nice or at least any way to get Block's Parent Page?
Let's say I have some Page which has some Block in some of it's ContentArea. How could I get that Page from outside Block's Model/Controller?
Ideally I would like to have a Property - ParentPage - on some Blocks, so I could the access some properties of that ParentPage when used in Block's view... does it makes sense?
CMS version is 11 something...
Thank you!