Reputation: 63
I have seen in umbraco code, where developers get reference to a content page, like this:
var content = UmbracoContext.PublishedContentRequest.IsInternalRedirectPublishedContent
? UmbracoContext.PublishedContentRequest.InitialPublishedContent
: UmbracoContext.PublishedContentRequest.PublishedContent;
BUT why do they do that ?
Why not use @ Model.Content ()
What is (What do they do):
IsInternalRedirectPublishedContent?
InitialPublishedContent ?
PublishedContent ?
Upvotes: 2
Views: 373
Reputation: 1985
In Umbraco there's a bunch of reserved properties you can put on documents to get some "hidden" functionality. One of them is umbracoInternalRedirectId
which allows you to do an internal redirect and render another node instead of the node being requested.
You can read more about some of those other reserved properties here.
In case you use the internal redirect, your request will internally be redirected to another node ID and then everything will be rendered as if you had initially requested that other node (you will however not see a browser redirect and it will not be reflected in the URL either).
What is (What do they do):
IsInternalRedirectPublishedContent?
This will be true if the content you are redirecting to, is currently published. False if the content is unpublished.
InitialPublishedContent ?
This will be the content item you are initially hitting (before the redirect happens).
PublishedContent ?
This will be the content item you are redirected to (this will be the same as the current content item you mention above).
BUT why do they do that ?
What is done above is to try to always get a reference to the initial content before any internal redirect happening in case of a redirect - and to just get the current content item if there's no internal redirect happening.
It however doesn't really seem to make sense to do this, considering that in case of IsInternalRedirectPublishedContent
returning false, InitialPublishedContent
will be the same as PublishedContent
.
You would get the same result as above by simply doing:
var content = UmbracoContext.PublishedContentRequest.InitialPublishedContent;
It may however be that this has not always been the case and that this piece of code was to work around a bug in an older version of Umbraco.
So I'd say unless you have a very strange redirect setup in your site, there should be no reason for not just using this piece of code instead of the one you posted.
To completely answer your question:
In the code above, using content
in your template, would be a reference to the page where the redirect is configured at. Using Model.Content
would be a reference to the node your are internally redirected to.
Upvotes: 3