Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 936 posts 2571 karma points
    Sep 04, 2015 @ 12:50
    Claushingebjerg
    0

    Using with leblender

    Im trying to use nested conted with "Le blender" to do some serious Grid magic... But i cant get it to render any output. Using this in a grid view partial:

    @using Umbraco.Web.Templates
    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    
    @foreach (var item in Model.Items)
        {
            var items = item.GetPropertyValue<IEnumerable<IPublishedContent>>("institutioner");
            foreach(var item in items) {
            <p>foo</p>
        }
    }
    

    i get "error CS1928: 'Lecoati.LeBlender.Extension.Models.LeBlenderValue' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue

    How do i render nested content in Leblender context?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 04, 2015 @ 12:59
    Lee Kelleher
    0

    Hi Claus,

    I've never tried Nested Content with LeBlender before... to be honest, I'm surprised to hear that they are compatible. (As I thought LeBlender was based on macro-parameter-editors).

    From the exception message, the problem appears to be how to get the value from the LeBlenderValue object.

    Looking on GitHub, the source-code shows that they have a GetValue<T> method.

    Try using GetValue instead of GetPropertyValue.

    Cheers,
    - Lee

  • Claushingebjerg 936 posts 2571 karma points
    Sep 04, 2015 @ 13:36
    Claushingebjerg
    0

    Yeah, i've been down that route a bit...

    if i just do:

    <p>@item.GetValue("institutioner")</p>
    

    i get the json:

    [ { "name": "Item 1", "ncContentTypeAlias": "Skole", "navn": "blah", "logo": "1078", "link": "http://www.dr.dk" }, { "name": "Item 2", "ncContentTypeAlias": "Skole", "navn": "werwer", "logo": "1073", "link": "http://www.google.dk" } ]
    

    if i do:

    <p>@item.GetValue<IEnumerable<IPublishedContent>>("institutioner")</p>
    

    i get this error:

    error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
    
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 04, 2015 @ 13:46
    Lee Kelleher
    0

    Is there anything more in the error CS1502?

  • Sven Geusens 169 posts 881 karma points c-trib
    Feb 21, 2017 @ 15:21
    Sven Geusens
    0
    <p>@item.GetValue<IEnumerable<IPublishedContent>>("institutioner")</p>
    

    This does not work since razorscript breaks of at the first < thinking its an html tag.

    You can resolve this by putting the whole statement in ()

    <p>@(item.GetValue<IEnumerable<IPublishedContent>>("institutioner"))</p>
    

    The reason why your first code didnt work is because you used .GetPropertyValue instead of GetValue

  • Claushingebjerg 936 posts 2571 karma points
    Sep 04, 2015 @ 13:50
    Claushingebjerg
    0

    Nope, its leblender returning the error message, not a full blown error page

  • Claushingebjerg 936 posts 2571 karma points
    Sep 04, 2015 @ 13:51
    Claushingebjerg
    0

    is

    <IEnumerable<IPublishedContent>>
    

    correct? It looks weirdly nested to me...

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 04, 2015 @ 13:57
    Lee Kelleher
    0

    Yeah, that's the correct syntax for the type. But I suspect that LeBlender is doing something differently than how Umbraco gets the property value.

    The error CS1502 doesn't really give us much to go on :-(

    I'd say that this isn't an issue with Nested Content, more how LeBlender is handling the property-value resolution.

    Maybe it is best to ask Antoine to join this thread, or raise a new thread on the LeBlender forum?

    Thanks,
    - Lee

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 04, 2015 @ 14:14
    Dave Woestenborghs
    0

    Hi Claus,

    I think we had this working in a project, but we used a Leblender controller and it worked in the controller.

    Dave

  • Claushingebjerg 936 posts 2571 karma points
    Sep 08, 2015 @ 11:07
    Claushingebjerg
    0

    Ok, so i found a way to do it, just if some else need to do the same. Using json.net i parse the raw json from nested content.

    @using Umbraco.Web.Templates
    @using Newtonsoft.Json.Linq
    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    @foreach (var item in Model.Items)
    {       
        string schools = item.GetValue("institutioner");
        var jArray = JArray.Parse(schools);
        if (jArray.Count > 0)
        {
            foreach (dynamic x in jArray)
            {
                <p>@x.navn, @x.link, @x.logo</p>
            }
        }
    }   
    
  • Claushingebjerg 936 posts 2571 karma points
    Sep 10, 2015 @ 09:17
    Claushingebjerg
    2

    Ok im at an absolute loss as to what happened... Suddenly the above json method didnt work anuymore... Now i use this:

    @using Umbraco.Web.Templates
    @using Newtonsoft.Json.Linq
    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    
    @foreach (var item in Model.Items)
        {       
            var items = item.GetValue<IEnumerable<IPublishedContent>>("institutioner");
            foreach(var nesteditem in items) {
            <p>@nesteditem.GetPropertyValue("navn")</p>
            }
        }
    

    why this suddenly works i have no idea. Hopefully it stays this way now...

  • Anders Brohus 194 posts 475 karma points
    Jul 18, 2016 @ 11:25
    Anders Brohus
    0

    Thanks Claus! :)

    I'm currently developing a block on my current project where i tried using Nested Content for the first time and your last code is working really well! :)

  • Tajamal 87 posts 175 karma points
    Feb 21, 2017 @ 14:03
    Tajamal
    0

    Has anyone got this working ?

    I have tried everything above, nothing is working for me with LebLender and Nested Content.

    Versions
    Vorto 1.5.3
    Umbraco 7.5.8
    LeBlender 1.0.8.4
    
  • Sven Geusens 169 posts 881 karma points c-trib
    Feb 21, 2017 @ 15:23
    Sven Geusens
    0

    Could you post any more relevant information?

  • Tajamal 87 posts 175 karma points
    Feb 22, 2017 @ 10:04
    Tajamal
    0
    var item =  Model.Items.FirstOrDefault();
    var items = item.GetValue<IEnumerable<IPublishedContent>>("institutioner");
    
    items returned is null 
    

    and it doesn't matter if I iterate Model.Item through foreach or as above, any suggestions ?

  • Tajamal 87 posts 175 karma points
    Feb 22, 2017 @ 10:43
    Tajamal
    0

    Another example

    Other thing might be that, I am using Multilanguage Vorto plugin which returns different json then above.

    var body = item.GetRawValue("body");
    

    returned json:

        {[
      {
        "name": "Item 1",
        "ncContentTypeAlias": "humanBody",
        "arms": {
          "dtdGuid": "d06ab40a-a3c6-44ae-8671-b84434445a8f",
          "values": {
            "en-US": "Arms",
            "da-DK": "Arme"
          }
        },
        "legs": {
          "dtdGuid": "d06ab40a-a3c6-44ae-8671-b84434445a8f",
          "values": {
            "en-US": "Legs",
            "da-DK": "Ben"
          }
        }
      }
    ]}
    
Please Sign in or register to post replies

Write your reply to:

Draft