Copied to clipboard

Flag this post as spam?

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


  • Steve 3 posts 73 karma points
    Mar 15, 2017 @ 13:59
    Steve
    0

    How to query nodes in a Custom Grid Editor?

    I was using this tutorial to create a custom editor https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/grid-layout/build-your-own-editor

    However in my custom render, i want to query a list of nodes to render as a menu but since this inherits from the UmbracoViewPage it doesnt seem to work the same way i used to in an UmbracoTemplatePage.

    Here is my code:

        @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
    
    @{
    
        var postNodes = Model.Content.AncestorOrSelf("Home").Descendants("Testimonial")
                        .Where(i => i.IsVisible()).Take(1);
    
    
        if (postNodes != null)
        {
            <section class="testimonials center">
                @foreach (var post in postNodes)
                {
                    var text = post.GetPropertyValue<string>("bodyText", recurse: true);
    
                    <blockquote>@text</blockquote>
                    <span class="testimonial-attribution prominent">@post.Name</span>
    
                }
    
            </section>
        }
    }
    

    Error: error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

  • Shashank Balooni 2 posts 72 karma points
    Mar 27, 2017 @ 09:45
    Shashank Balooni
    0

    Hi Steve, You could just use the Current Page to Query through.

    var CurrentPage = Umbraco.Content(umbraco.NodeFactory.Node.GetCurrent().Id);

    Here I have used the Node Factory to get the Current Node ID and Used the Umbraco helper to get the Published Content. Now I have the Current Node.

    var articlePost = CurrentPage.AncestorOrSelf(1).Descendants("Testimonial").Take(1);
    

    Here I have Used the AncestorOrSelf(level) to navigate back to the Root that is given as 1(Root Level is 1).

    Using Descendants I have tried to find all documents of the Document Type alias ("Testimonials").

    Document Type Alias is case sensitive. Please do check if you are passing the correct document type alias..

    Take 1 does what it does in asp.net.; it takes one out of all those results.

    Hope this helps.

Please Sign in or register to post replies

Write your reply to:

Draft