Year i know its nice if all you have to work with is in the "Templates" or "Controllers"
but if u opt in before these have run then it seem a bit hard to fetch the node based on that "uri as unique identifier" And it shouldnt be hard at all. Umbraco.TypedContent() should have and overload to work with and uri. Just like firebase has (that actualy uses the same "pattern" for unique identifers.)
In my issue i have to access the multi node picker in the examine index event, cause i need to "tokenize" the fields to make em usefull for searching.
So i gues i have to look at the implementation of the Core.PropertyConverter to see how it is resolved and then do the same in the GathernodeEvent.
Can u remember what assembly the PropeprtyValueConverters are placed in ?
Basically, ToPublishedContent() is bad, and will be obsoleted in the very near future (possibly next patch release) and we'll be able to use the standard UmbracoHelper.TypedContent() method and friends instead.
I am unable to fetch content info with a Uid. I can't find a solution anywhere Model.Content.GetPropertyValue<IPublishedContent>(uid) always returns null.
While troubleshooting my issues, I tried querying the umb://document/guid and umb://media/guid from the MacroPartialView and a Template Page. Using Model.Content.GetPropertyValue<IPublishedContent>(###) and neither worked.
What I'm asking is how do I get the typed content when faced with the guid instead of the node id within a view.
You can't pass a string in, the parameter of GetPropertyValue must be the alias of a property on the model, in this case the alias of a media picker or content picker that can return as IPublishedContent
Hi, related question to this... how can I use the Backoffice UI API to get content by Udi? I've checked the latest version of the ContentController in UmbracoApi and it still only takes int id to retrieve content.
I've been struggling with this issue as well. I need the URL's for a RelatedLinks collection exposed on a model generated by Models Builder (Umbraco v 7.6.4). Here is a code snippet of the only way I could find to resolve this issue, and I don't like it because I'm forced to use the ContentService:
[ImplementPropertyType("services")]
public Umbraco.Web.Models.RelatedLinks Services
{
get
{
// will need to perform this operation on all related links in the collection
var relatedLink = this.GetPropertyValue<Umbraco.Web.Models.RelatedLinks>("services").First();
var udiGuid = (Guid)Udi.Parse(relatedLink.Link).ToDictionary()["Guid"];
var page = ApplicationContext.Current.Services.ContentService.GetById(udiGuid);
var url = new global::umbraco.MacroEngines.DynamicNode(page.Id).NiceUrl;
// returns null
var helper = new UmbracoHelper(UmbracoContext.Current);
var pageTypedContent = helper.TypedContent(Udi.Parse(relatedLink.Link));
return this.GetPropertyValue<Umbraco.Web.Models.RelatedLinks>("services");
}
}
The UmbracoHelper.TypedContent method returns null when I pass it the Uid.
So here is how I handle this. I miss the pages when it was just a simple list of Ids.
Here are two methods I use for getting this data. You have a choice of simply passing the string in or passing in the UDI.
public static IPublishedContent GetPublishedContentByUdi(string udi)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
return umbracoHelper.TypedContent(udi);
}
public static IPublishedContent GetPublishedContentByUdi(Udi udi)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
return umbracoHelper.TypedContent(udi);
}
If you do pass in the Udi here is a handy bit of code you might find useful.
Although I didn't get so elegant as to make an overload further back in the code, this actually set me on the correct path for how to address this issue in Umbraco 8. THANK YOU!
EDIT:As a side note, Umbraco.TypedContent is now Umbraco.PublishedContent.
But I also note that Umbraco.Content has way more overloads than Umbraco.PublishedContent does. I hope I am not using a method that is going out of style...
Using the new umb:document/guid
Hey Experts
i just played around with 7.6 and i saw that it saves entries in the content picker and multinode picker in a new format
"umb://document/b3fc5438670444f38ddcc34adbaa44a7"
How do i get the content based on that Uri ? could replace me out of the issue but it seems stupid :)
any one has and idea ?
Hi Peter,
Umbraco v7.6 includes value converters by default so now it returns IPublishedContent from the content picker.
So you can do things like
Or even better use Models Builder then you can do things like:
Jeavon
Hey Jeavon
Year i know its nice if all you have to work with is in the "Templates" or "Controllers"
but if u opt in before these have run then it seem a bit hard to fetch the node based on that "uri as unique identifier" And it shouldnt be hard at all. Umbraco.TypedContent() should have and overload to work with and uri. Just like firebase has (that actualy uses the same "pattern" for unique identifers.)
In my issue i have to access the multi node picker in the examine index event, cause i need to "tokenize" the fields to make em usefull for searching.
So i gues i have to look at the implementation of the Core.PropertyConverter to see how it is resolved and then do the same in the GathernodeEvent.
Can u remember what assembly the PropeprtyValueConverters are placed in ?
Hi Peter,
Ok, in that case you can do this:
Jeavon
See the note on a similar forum topic here:
https://our.umbraco.org/forum/templates-partial-views-and-macros/85703-macro-parameter-to-ipublishedcontent#comment-272529
Basically,
ToPublishedContent()
is bad, and will be obsoleted in the very near future (possibly next patch release) and we'll be able to use the standardUmbracoHelper.TypedContent()
method and friends instead.Rob.
Thx alot jeavon :) just what i was looking for
where did u find it in the core ? :)
I have seen it somewhere in Core recently but I don't remember where, I used VS Intellisense on Udi to check it
It seemed soooo nice at first glance. But the extension method ToPublishedContent is using the UmbracoContext.current witch is null on
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += SpecialityIndexer_GatheringNodeData; }
So i have to go down the entity Service road :(
TBH i love the URI mindset on content. but the API needs som more helper methods to make it smooth :)
Interesting one, can you use udi.AsGuid() then pass the Guid into TypedContent?
Or maybe StringUdi.Parse("myUdi").Id
Hmm i played a bit around with it now and it seems like the chain is broken somewhere.
string id = "umb://document/b3fc5438670444f38ddcc34adbaa44a7";
var demo = StringUdi.Parse(id); Throws and error that my string is not a valid stringUid
and if i look a the core code it seems like Stringuid is used for something els cause it uses Uid.Parse and then test if it gets a StringUid back.
udi.AsGuid() gives same error as Udi.Parse("myUdi").ToPublishedContent()
i can get around it with :
It just seems strange that my Picker saves a value that i have trouble using.
lets take some filters and news as example. The editor can create filters under some node and then afterwards tag news with those.
i would have to resolve either a uid to a id or some id's to uid to make a proper filter.
hmm maybe the IPublishedContent has and Uid property now and the best solution is to convert to it and use it instead of int Id.
Is there any solution to this?
I am unable to fetch content info with a Uid. I can't find a solution anywhere
Model.Content.GetPropertyValue<IPublishedContent>(uid)
always returns null.Greg, how are you getting your UDI?
Peter's scenario was quite specific to retrieving UDI's directly from Examine.
Hey Jeavon,
I'm inside a PartialViewMacro File.
Both
@Model.MacroParameters[]
returnubm://document/guid
andubm://media/gui
I've tried
@Model.Content.GetPropertyValue<IPublishedContent>(Model.MacroParameters["###"].ToString())
and I get null (### = either parameter)Hi Greg,
Ok, in that case try this:
Jeavon
Hi Jeavon,
Thanks that works.
Is this how we'll need to query content from now on with the change from node Ids to guid?
Hi Greg,
No not normally in a View or Partial, this is only because you are passing the UDI through the macro to the MacroPartialView.
Jeavon
Jeavon,
While troubleshooting my issues, I tried querying the
umb://document/guid
andumb://media/guid
from the MacroPartialView and a Template Page. UsingModel.Content.GetPropertyValue<IPublishedContent>(###)
and neither worked.What I'm asking is how do I get the typed content when faced with the guid instead of the node id within a view.
Hi Greg,
If you were in a View then
Model.Content.GetPropertyValue<IPublishedContent>("myMediaPickerPropertyAlias")
would have worked.Jeavon
Jeavon,
Thanks for your patience and thanks for answering all my questions.
Regarding your last reply. What I'm saying is this is my template:
While troubleshooting the problem earlier, I did this:
Where I know, for a fact, that
umb://document/68c8d8f273b04601a7e7d914b1cff0ab
is an existing published document. Andtest
returnsnull
.You can't pass a string in, the parameter of GetPropertyValue must be the alias of a property on the model, in this case the alias of a media picker or content picker that can return as IPublishedContent
Right... I get it now. I think it just clicked in my head.
Thanks for your help.
Hi, related question to this... how can I use the Backoffice UI API to get content by Udi? I've checked the latest version of the ContentController in UmbracoApi and it still only takes int id to retrieve content.
Thanks @Jeavon Leopold, Your solution solved my problem
I've been struggling with this issue as well. I need the URL's for a RelatedLinks collection exposed on a model generated by Models Builder (Umbraco v 7.6.4). Here is a code snippet of the only way I could find to resolve this issue, and I don't like it because I'm forced to use the ContentService:
The UmbracoHelper.TypedContent method returns null when I pass it the Uid.
People having issues with Empty UDIs might want to check out this thread and my answer there.
Hi People,
So here is how I handle this. I miss the pages when it was just a simple list of Ids.
Here are two methods I use for getting this data. You have a choice of simply passing the string in or passing in the UDI.
If you do pass in the Udi here is a handy bit of code you might find useful.
I also wrote a blog about this since its troubled me a few times recently. https://www.umbrajobs.com/blog/posts/2018/june/umbraco-using-the-new-umbdocumentguidudi/
Kind Regards
David Armitage www.umbrajobs.com
Although I didn't get so elegant as to make an overload further back in the code, this actually set me on the correct path for how to address this issue in Umbraco 8. THANK YOU!
EDIT:As a side note, Umbraco.TypedContent is now Umbraco.PublishedContent.
I might be mistaken, but I think
is
in v8
I do not know if you are mistaken. The context I was using it in is below.
Below when I changed PublishedContent to Content, the code went ysod:
But I also note that Umbraco.Content has way more overloads than Umbraco.PublishedContent does. I hope I am not using a method that is going out of style...
is working on a reply...