Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Jensen 32 posts 137 karma points
    Apr 11, 2017 @ 12:30
    Peter Jensen
    1

    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 ?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 11, 2017 @ 13:48
    Jeavon Leopold
    101

    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

    @Model.Content.GetPropertyValue<IPublishedContent>("myContentPickerAlias").Name
    

    Or even better use Models Builder then you can do things like:

    @Model.Content.MyContentPickerAlias.Name
    

    Jeavon

  • Peter Jensen 32 posts 137 karma points
    Apr 12, 2017 @ 10:24
    Peter Jensen
    2

    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 ?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 12, 2017 @ 10:31
    Jeavon Leopold
    1

    Hi Peter,

    Ok, in that case you can do this:

    Udi.Parse("myUdi").ToPublishedContent()
    

    Jeavon

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    May 24, 2017 @ 23:51
    Robert Foster
    0

    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 standard UmbracoHelper.TypedContent() method and friends instead.

    Rob.

  • Peter Jensen 32 posts 137 karma points
    Apr 12, 2017 @ 10:48
    Peter Jensen
    0

    Thx alot jeavon :) just what i was looking for

    where did u find it in the core ? :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 12, 2017 @ 11:01
    Jeavon Leopold
    0

    I have seen it somewhere in Core recently but I don't remember where, I used VS Intellisense on Udi to check it

  • Peter Jensen 32 posts 137 karma points
    Apr 12, 2017 @ 11:21
    Peter Jensen
    0

    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 :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 12, 2017 @ 11:46
    Jeavon Leopold
    0

    Interesting one, can you use udi.AsGuid() then pass the Guid into TypedContent?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 12, 2017 @ 11:59
    Jeavon Leopold
    0

    Or maybe StringUdi.Parse("myUdi").Id

  • Peter Jensen 32 posts 137 karma points
    Apr 12, 2017 @ 14:59
    Peter Jensen
    0

    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 :

    Udi udi;
                    if (Udi.TryParse(id, out udi))
                    {
                        var guid = GuidUdi.Parse(udi.ToString());
                        IEntityService entityService = ApplicationContext.Current.Services.EntityService;
    
                        Attempt<int> response = entityService.GetIdForKey(guid.Guid, UmbracoObjectTypes.Document);
                        if (response.Success)
                        {
                            path += response.Result;
                        }
                    }
    

    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.

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 15:13
    Greg
    0

    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.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 05, 2017 @ 15:18
    Jeavon Leopold
    0

    Greg, how are you getting your UDI?

    Peter's scenario was quite specific to retrieving UDI's directly from Examine.

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 15:25
    Greg
    0

    Hey Jeavon,

    I'm inside a PartialViewMacro File.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    <div class="col-sm-3">
        <img src="@Umbraco.Media(Model.MacroParameters["Image"].ToString()).Url alt="@Model.MacroParameters["Title"].ToString()">
        <div class="title">
            @Model.MacroParameters["Title"].ToString()
        </div>
        <a href="@Model.MacroParameters["Link"].ToString()" class="btn btn-blue-clear">LEARN MORE</a>
    </div>
    

    Both @Model.MacroParameters[] return ubm://document/guid and ubm://media/gui

    I've tried @Model.Content.GetPropertyValue<IPublishedContent>(Model.MacroParameters["###"].ToString()) and I get null (### = either parameter)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 05, 2017 @ 15:59
    Jeavon Leopold
    3

    Hi Greg,

    Ok, in that case try this:

    @using Umbraco.Web.Extensions
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        Udi udi;
        if (Udi.TryParse(Model.MacroParameters["Image"].ToString(), out udi))
        {
            var mediaItem = udi.ToPublishedContent();
    
            <div class="col-sm-3">
                <img src="@mediaItem.Url" alt="@Model.MacroParameters["Title"].ToString()">
                <div class="title">
                    @Model.MacroParameters["Title"].ToString()
                </div>
                <a href="@Model.MacroParameters["Link"].ToString()" class="btn btn-blue-clear">LEARN MORE</a>
            </div>
        }
    }
    

    Jeavon

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 17:06
    Greg
    0

    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?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 05, 2017 @ 17:20
    Jeavon Leopold
    0

    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

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 17:26
    Greg
    1

    Jeavon,

    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.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 05, 2017 @ 17:31
    Jeavon Leopold
    0

    Hi Greg,

    If you were in a View then Model.Content.GetPropertyValue<IPublishedContent>("myMediaPickerPropertyAlias") would have worked.

    Jeavon

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 17:55
    Greg
    0

    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:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.HomePage>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <div class="row">
        @Html.Raw(Model.Content.GetProperty("LearnMoreBoxes").Value)
    </div>
    <div class="row">
        <div class="col-sm-8">
            @Model.Content.Main
        </div>
        <div class="col-sm-4">
            @Umbraco.RenderMacro("RecentUpdates")
        </div>
    </div>
    

    While troubleshooting the problem earlier, I did this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.HomePage>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <div class="row">
        @Html.Raw(Model.Content.GetProperty("LearnMoreBoxes").Value)
    </div>
    <div class="row">
        <div class="col-sm-8">
            @Model.Content.Main
    
            ---
    
            @{ var test = Model.Content.GetPropertyValue<IPublishedContent>("umb://document/68c8d8f273b04601a7e7d914b1cff0ab"); }
            @test.Url;
        </div>
        <div class="col-sm-4">
            @Umbraco.RenderMacro("RecentUpdates")
        </div>
    </div>
    

    Where I know, for a fact, that umb://document/68c8d8f273b04601a7e7d914b1cff0ab is an existing published document. And test returns null.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 05, 2017 @ 17:58
    Jeavon Leopold
    0

    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

  • Greg 25 posts 103 karma points
    May 05, 2017 @ 18:05
    Greg
    0

    Right... I get it now. I think it just clicked in my head.

    Thanks for your help.

  • Ryan 24 posts 106 karma points
    Jul 06, 2017 @ 05:02
    Ryan
    0

    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.

  • Sumesh KP 35 posts 108 karma points c-trib
    Jul 27, 2017 @ 05:07
    Sumesh KP
    0

    Thanks @Jeavon Leopold, Your solution solved my problem

  • Kevin Thomas 14 posts 93 karma points
    Jul 28, 2017 @ 02:17
    Kevin Thomas
    0

    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.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 28, 2017 @ 07:24
    Dan Diplo
    0

    People having issues with Empty UDIs might want to check out this thread and my answer there.

  • David Armitage 508 posts 2078 karma points
    Jul 20, 2018 @ 13:30
    David Armitage
    1

    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.

    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.

    Udi udi = Udi.Parse("umb://document/d4741f7f7acc4791a4dcb46f89b9f0b8");
    

    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

  • Bryna 74 posts 260 karma points
    Mar 12, 2019 @ 14:55
    Bryna
    0

    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.

  • Michael Nielsen 154 posts 811 karma points
    Mar 12, 2019 @ 15:03
    Michael Nielsen
    0

    I might be mistaken, but I think

    Umbraco.TypedContent 
    

    is

    Umbraco.Content
    

    in v8

  • Bryna 74 posts 260 karma points
    Mar 12, 2019 @ 21:29
    Bryna
    0

    I do not know if you are mistaken. The context I was using it in is below.

    string filePath = Umbraco.PublishedContent(Udi.Parse(item.DocumentID)).Url;
    

    Below when I changed PublishedContent to Content, the code went ysod:

    string filePath = Umbraco.Content(Udi.Parse(item.DocumentID)).Url;
    

    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...

Please Sign in or register to post replies

Write your reply to:

Draft