accessing current Published Content from ViewStart in Umbraco 13
Hi - I wanted to dynamically set the main Layout View used based on some doctype hierarchy rules using the current content context. I thought the special aspnet ViewStart would be a good place for this logic to reside.
However, this didn't work:
var currentpage = umbraco.AssignedContentItem;
with the error:
InvalidOperationException: Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent.
but this does:
var currentpage = _umbracoContextAccessor?.GetRequiredUmbracoContext()?.PublishedRequest?.PublishedContent;
The first approach feels "nicer" but anyone able to explain the technicallies of why that doesn't work but the context accessor way does?
accessing current Published Content from ViewStart in Umbraco 13
Hi - I wanted to dynamically set the main Layout View used based on some doctype hierarchy rules using the current content context. I thought the special aspnet ViewStart would be a good place for this logic to reside.
However, this didn't work:
with the error: InvalidOperationException: Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent.
but this does:
The first approach feels "nicer" but anyone able to explain the technicallies of why that doesn't work but the context accessor way does?
thanks
is working on a reply...