Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    May 04, 2015 @ 13:35
    René Andersen
    0

    Always use same rootNode

    Hi,

    I am using some data from a folder called data which is on the same level as home. How is it possible to always keep the same rootNode. I use the code below but it does not work. When I fetch data from the data folder, then it changes the navigation so that it shows all the items in the data folder.

    var home = @CurrentPage.Site();

    My structure looks like this:

    Is there a way to always use the exact same rootNode regardless if the content is from the data folder or home folder?

    // René

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 04, 2015 @ 13:55
    Jan Skovgaard
    0

    Hi René

    What does your full code look like where you experience this issue?

    If you don't attach a template to the date elements then they should not be populated with a URL either if I remember correctly.

    But it would be nice to see the full code that is causing the issue - I have used a similar approach as the one you illustrate on the image above and not had any trouble with changes in navigation even though I loaded content from the "Data/Elements" section...so need to see the issue in action :)

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 04, 2015 @ 14:12
    Chriztian Steinmeier
    3

    Hi René,

    That actually makes sense, because .Site() goes all the way up to level 1, so when you're in the "Forside" section it'll return Forside, and in the Data section, the Data node will be hit. What you really want is to go all the way to the root node and then pick the Forside node below that - something like this:

    var home = @CurrentPage.Root().Down("ForsideAlias");
    

    This should work if I understand this page correct.

    "ForsideAlias" should of course be replaced with the actual nodeTypeAlias of your "Forside" node

    /Chriztian

  • René Andersen 238 posts 684 karma points
    May 04, 2015 @ 14:34
    René Andersen
    0

    Hi Jan and Chriztian

    Chriztian:
    I did not manage to get it working with your example.

    Jan:
    See my code below:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ var selection = CurrentPage.Site().Children.Where("Visible"); }

    <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
    <div class="container">
    <div class="collapse navbar-collapse" id="custom-collapse">
    <ul class="nav navbar-nav navbar-right">
    @foreach (var item in selection)
    {
    <li class="@(item.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
    <a href="@item.Url">@item.Name</a>
    </li>
    }
    </ul>
    </div>
    </div>
    </nav>

    On this project it is very important that almost all data / content is stored in the data folder, because it should be very easy to change the frontpage to another layout / template without deleting all the children below the frontpage.

    // René

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 04, 2015 @ 14:44
    Jan Skovgaard
    0

    Hi René

    Ok, I understand your issue now.

    But wondering what did not work when you tried using Chriztians example? Did you get a yellow screen of dead? If so what did the error message say? And what did the error message in the /app_data/logs file say?

    It should be fairly easy to achieve what you want using CurrentPage.AncestorOrSelf(1).Children.Where("Visiable") otherwise though - But since .Site() should do that for you according to what Chriztian writes above it might be more conventional to use that approach :)

    Looking forward to hearing from you.

    /Jan

  • René Andersen 238 posts 684 karma points
    May 04, 2015 @ 14:59
    René Andersen
    0

    Hi Jan

    No the navigation just disappears on every page.

    // René

  • René Andersen 238 posts 684 karma points
    May 04, 2015 @ 18:05
    René Andersen
    0

    I am following Chriztian's example. Try to see this code, am I doing something wrong?

    @{ var home = @CurrentPage.Root().Down("HomeSlider"); }

    <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
    <div class="container">
    <div class="collapse navbar-collapse" id="custom-collapse">
    <ul class="nav navbar-nav navbar-right">
    <li><a href="/">Forside</a></li>
    @foreach (var item in home)
    {
    <li>
    <a href="@item.Url">@item.Name</a>
    </li>
    }
    </ul>
    </div>
    </div>
    </nav>

    // René

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 05, 2015 @ 00:46
    Chriztian Steinmeier
    100

    Hi René,

    The home variable points to the Forside node, so you need to iterate its children and not itself, e.g.:

    @foreach (var item in home.Children)
    {
        output...
    }
    

    /Chriztian

  • René Andersen 238 posts 684 karma points
    May 15, 2015 @ 14:42
    René Andersen
    0

    Hi Chriztian

    That's perfect now it is working.

    Thanks!

    // René

Please Sign in or register to post replies

Write your reply to:

Draft