Copied to clipboard

Flag this post as spam?

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


  • Levente Kosa 136 posts 352 karma points
    Jun 28, 2015 @ 11:42
    Levente Kosa
    0

    List all nodes by node nodeTypeAlias(es)

    Hi,

    I would like a like with all nodes from home page through all the site by different node nodeTypeAliases. Is that possible somehow using razor? So far I have this:

    @{
        dynamic root = @Umbraco.Content(1060);
        var news_items = root.Descendants("type1")
    }
    <ul>
        @foreach (var news_item in news_items)
        {
            <li>
                @news_item.Name
            </li>
        }
    </ul>
    
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jun 28, 2015 @ 12:01
    Dennis Aaen
    0

    Hi Levente,

    WIth this code below should list pages from home page through all the site by different nodes.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{  var selection = CurrentPage.AncestorOrSelf(1).Descendants("umbNewsItem").Where("Visible"); }
    
    @if (selection.Any())
    {
        <ul>
            @foreach (var item in selection)
            {
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
    }
    

    By doing it by this way, then you donĀ“t need to use a specific id, to get data from. The id can change if the user delete the homepage and create again, then it will get another id, than 1060.

    Remember to change the document type alias so it match your case.

    Hope this helps,

    /Dennis

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jun 28, 2015 @ 12:08
    Dennis Aaen
    100

    And if you want to list more nodes by more than one DocumentTypeAlias then you can do by this way.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{  var selection = CurrentPage.AncestorOrSelf(1).Descendants().Where("Visible").Where("DocumentTypeAlias == @0 || DocumentTypeAlias == @1","umbNewsItem","umbTextPage"); }
    
    @if (selection.Any())
    {
        <ul>
            @foreach (var item in selection)
            {
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
    }
    

    In the example above I list nodes that uses the document types with the aliases of "umbNewsItem" and "umbTextPage"

    Hope this helps,

    /Dennis

  • Levente Kosa 136 posts 352 karma points
    Jun 28, 2015 @ 12:20
    Levente Kosa
    0

    Hi Dennis,

    It's perfect, again. It seems you are my hero today :)

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jun 28, 2015 @ 12:25
    Dennis Aaen
    0

    Hi Levente,

    You are welcome. Great that it works like intended. I am glad that I can help you.

    /Dennis

  • Levente Kosa 136 posts 352 karma points
    Jul 02, 2015 @ 21:08
    Levente Kosa
    0

    Hi Dennis,

    Sorry, that I interrupt again, but I have a really big problem. It's totally different problem like this, just unfortunately nobody knows what is the solution for my problem, and it's very important. Can you have a look at this link, if it's not a big problem? Maybe you know the answer or have a solution: https://our.umbraco.org/forum/getting-started/questions-about-runway-and-modules/67065-save-problem-after-100-images

    Thank you, Levente

Please Sign in or register to post replies

Write your reply to:

Draft