Copied to clipboard

Flag this post as spam?

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


  • Christoffer Lilja 5 posts 25 karma points
    May 10, 2015 @ 12:38
    Christoffer Lilja
    0

    List news on startpage using grid editor

    First of all I'm completely new to Umbraco, so please bare with me.

    I'm using the Fanoe starterkit and I'm trying to display some of the blog-posts on the startpage. To do this I created a grid edit control, made it possible to add it to a grid row configuration and added it to the startpage.

    So far so good but I can't figure out how to query the api to get and display the blog-pages. I'd like to use the same layout as the blogoverview.cshtml

    If I do

    var test = Model.Content.Children.Single(x => x.DocumentTypeAlias == "BlogPostRepository");
    

    I get

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

    I've also tried different version of Model.AncestorOrSelf(1) without any luck.

    Would you do it like this or is it a better way?

    I've read and followed

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 10, 2015 @ 13:26
    Dennis Aaen
    0

    Hi Christoffer and welcome to our,

    Since you are using Umbraco 7.2 you can use the query builder when you are in a template. It´s the last button on the ribbon, see the picture below,

    You can see this Razor snippet to show blogposts on your home template, you can do it directly into your homepage template. or in a partial view or partial view macro file.

    @{
        var selection = CurrentPage.Site().FirstChild("BlogPostRepository").Children("BlogPost").Where("Visible");
    }
    <ul>
        @foreach(var item in selection){
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>

    Hope this helps,

    /Dennis

  • Christoffer Lilja 5 posts 25 karma points
    May 10, 2015 @ 14:50
    Christoffer Lilja
    0

    Thank you! Didn't notice that before, but then I hard code news/blog posts into a document template. That's what I was trying to avoid and was thinking that creating a grid edit would let me move around "modules" in the content editor.

    But how do I access the content tree and items from inside the grid editors .cshtml? The .cshtml file of the grid editor is using @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic> and it doesn't seem to have a CurrentPage or Model.AncestorOrSelf(1)?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 10, 2015 @ 15:00
    Dennis Aaen
    0

    Hi Christoffer,

    If I remember correctly then when you are using @inherits Umbraco.Web.Mvc.UmbracoViewPage you are in strongly typed Razor. The way you get the current page in strongly typed Razor, is by using:

    @Model.Content.AncestorOrSelf(1)

    Hope this helps,

    /Dennis

  • Christoffer Lilja 5 posts 25 karma points
    May 10, 2015 @ 16:31
    Christoffer Lilja
    0

    Thank you for trying to help me but that line gives me Cannot perform runtime binding on a null reference

    I also believe you misspelled Content but I changed that. I'm out of luck here. Does a grid editor only have access to it's own values? Looking at the other grid editors that exists in Umbraco/Fanoe they use @Model.value.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 10, 2015 @ 16:49
    Dennis Aaen
    0

    Hi Christoffer,

    When you say the grid editor, did you then mean the grid layout https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/grid-layout. If so there are some limitationswhen you are using it. One of the limitations is:

    First of all, all content entered into the grid is stored as a single property value on the content node, as a big JSON object. This means that as soon as the values are stored in the database, there is no managed api to drill into the grid content and target specific cell content - so a grid layout is not a recommended storage of reusable content.

    See the documentation here: https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Grid-Layout-Best-Practices

    If you want to build your own property editor try to see this http://umbraco.tv/videos/umbraco-v7/developer/extending/property-editors/introduction/ video chapter on Umbraco TV, or other videos, You can see the different plans here: http://umbraco.tv/plans-signup/

    Hope this helps,

    /Dennis

  • Christoffer Lilja 5 posts 25 karma points
    May 10, 2015 @ 17:52
    Christoffer Lilja
    0

    Hello Dennis,

    Yes I mean the grid layout. But I don't use it to store anything. It's just a "dumb editor" whose only purpose is to list content from other parts of the content three. I want to use it to be able move around "modules" in the content editor.

    In this case the Fanoe starter kit has an area called blog. I would like to list all the blog posts under that blog-node using the .cshtml of my grid edit control. Everything is working perfectly except I can't figure out how to traverse trough the content three using the grid edit .chtml

    Since I'm new there is probably a better way to do this. If so please point me in a that direction :)

    I've changed the name of the blog section to news, nothing more.

    editing the start page

    Looking at the start page

  • Christoffer Lilja 5 posts 25 karma points
    May 12, 2015 @ 10:45
    Christoffer Lilja
    0

    Ok, I'm stuck here. If it's not possible to read the content three from the grid edit .cshtml file how would you normally query Umbraco, if you have the context but nothing else?

  • Amir Khan 1287 posts 2744 karma points
    Aug 21, 2015 @ 19:41
    Amir Khan
    0

    So is there no way to traverse the tree from a grid layout editor?

    I'm just trying to grab some properties from the homepage...

    Thanks!

    Amir

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Aug 24, 2015 @ 06:49
    David Brendel
    0

    I don't know a way to traverse the tree in a grid editor.

    Think a workaround would be to trigger an API call that traverse the tree and gather the data.

    If it is just for displaying a list Luke blog post I would prefer a macro for this job and not a new grid editor.

  • Amir Khan 1287 posts 2744 karma points
    Aug 24, 2015 @ 21:09
    Amir Khan
    0

    It isn't, I'm trying to grab some values from the homepage of the site to populate a map.

Please Sign in or register to post replies

Write your reply to:

Draft