Copied to clipboard

Flag this post as spam?

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


  • Alejandro Ocampo 67 posts 330 karma points c-trib
    May 26, 2016 @ 09:35
    Alejandro Ocampo
    0

    DocType Grid Editor is not rendering the property values on 7.4.3

    Hi,

    I'm using nested content & doctype grid editor and when I try to render the property values, the values are not being mapped using:

    var t = Model.GetPropertyValue<string>("title");
    var y = Umbraco.Field(Model, "title");
    

    But the output is: y | {} | System.Web.IHtmlString {System.Web.HtmlString}

    The DataValue of the Model is:

    [{"name":"This is AWESOME","ncContentTypeAlias":"headline","title":"This is AWESOME","useBreadcrumb":"1"}]
    

    Any ideas?

    For the time being I've created this:

    public static class InternalDocTypeGridEditorHelper
    {
        public static List<Dictionary<string, string>> GetPropertyValues(IPublishedProperty docTypeGridEditorProperty)
        {
            var jsonDataValue = docTypeGridEditorProperty?.DataValue;
            if (jsonDataValue == null) { return null; }
    
            var properties = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonDataValue.ToString());
            return properties;
        }
    }
    

    Thanks, Ale

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 26, 2016 @ 13:27
    Lee Kelleher
    1

    Hi Ale,

    You were pretty close! Cutting a to the chase, this is what you want...

    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("title");
    

    That will give you the strongly-typed IPublishedContent nodes.


    The issue with using Model.GetPropertyValue<string>("title") is that you are asking for a string object type, so that's what you get... but because of how NestedContent's property-value converter works, it would be a string of an IPublishedContent, which I would expect to literally be "Umbraco.Core.Models.IPublishedContent".

    As for using Umbraco.Field ... eek, I'm not sure how exactly Umbraco internals work on that. To be honest, I wouldn't expect it to work, as I think it queries the content-cache, but that's outside of NestedContent's scope ... as frustrating as that may be :-(

    I hope this helps?

    Cheers,
    - Lee

  • Alejandro Ocampo 67 posts 330 karma points c-trib
    May 26, 2016 @ 14:21
    Alejandro Ocampo
    0

    Hi Lee,

    Thanks for your answer, that line doesn't return the values either, nulls every where.

    Would be good to have some sort of extension to map the values as needed, more umbraco-ish way.

    var items = Model.GetDocTypeGridEditorPropertyValue<string>("title");
    

    Thanks, Ale

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 26, 2016 @ 15:05
    Jeroen Breuer
    1

    A bit offtopic but for Nested Content and the Doc Type Grid Editor you both need doctypes. With the Models Builder you can generate models for those doctypes and map to those models.

    Check the "Using with the Models Builder" part of this blog: http://24days.in/umbraco/2015/multilingual-vorto-nested-content/

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 26, 2016 @ 15:22
    Matt Brailsford
    101

    Hi Ale,

    I think there is a bit of info missing. What is you NC property called on your DTGE doc type? As I think you'll need to do something like

    var ncItems = Model.GetPropertyValue<IEnumberable<IPublishedContent>>("ncPropAlias");
    
    foreach(var item in ncItems){
        var title = item.GetPropertyValue("title");
    }
    

    or, if you only have one item in your NC list, something like:

    var title = Model.GetPropertyValue<IEnumberable<IPublishedContent>>("ncPropAlias").First().GetPropertyValue("title");
    

    @jeroen appreciate your help but I kinda feel introducing models builder would just complicate the matter so lets try to stick to the question at hand (it does come across a little spammy as well so do be careful)

  • Alejandro Ocampo 67 posts 330 karma points c-trib
    May 26, 2016 @ 15:54
    Alejandro Ocampo
    0

    Hi @Matt,

    You were right I was trying to get the properties using the of the actual property alias (title) instead of using the NC property alias.

    I'm clear now and it working.

    @Jeroen I'll have a look to your suggestion :)

    Thank you so much!

    Ale

Please Sign in or register to post replies

Write your reply to:

Draft