Hi
I have a controller/class where a method in this class is being called to get a page programmatically.
As an example, in Umbraco 13 I have 2 pages. When I'm on page 2, I'm calling this method to get some details from page 1.
I can get it by IContent (GetById) or some documents suggest using IPublishedContent.
Which is the correct way to get this type of record?
Thanks
It was that link that led me to asking this question 😀
If using IPublishedContent then I don't see a method to get page by guid?
s
Sebastiaan
04/17/2024, 12:52 PM
Yes, you can always get it by Guid for
IPublishedContent
. Show some code where you're stuck and we'll have a look.
t
TigerMan
04/17/2024, 12:59 PM
I think I've worked it out.
I added UmbracoHelper in my constructor and did:
Var con = umbracHelper.Content(myGuid);
This seems to have worked, is this the correct way to retrieve the page contents?
s
Sebastiaan
04/17/2024, 1:04 PM
that looks about right yeah, as long as it gives you an
PublishedContent
!
one tip, if you already have a content item, then
content.Key
will give you the
Guid
of that item. I don't know if that's the case for you but it might be useful.