Copied to clipboard

Flag this post as spam?

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


  • Simon Bowler 14 posts 34 karma points
    Mar 23, 2012 @ 13:52
    Simon Bowler
    0

    Display child nodes as links for current folder

    Hi,

    I am new to umbraco and razor, I have has a look around but cant find the answer to my question.

    I have a the following website structure, which I am building the new pages in "our services "

     

    I want to display the child pages of our services as nav, I have the following code

    <!-- New dynmaic way of pulling nav -->
                <umbraco:Macro runat="server" language="cshtml">
      
                   @foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible"))
                    {
      
                    <ul>
                     @foreach (var subpage in page.Children.Where("Visible"))
                     {
                      <li><a href="@subpage.Url">@subpage.Name</a></li>
                     }
                    </ul>
                    }
    But this coxde displays all the child pages of all the nodes (eg child pages of, content rows, set a record, explorer record)
    I just want it to show child nodes of that specific folder
    Any help would be great, thanks

     

     

  • Paul Stewart 50 posts 71 karma points
    Mar 23, 2012 @ 14:22
    Paul Stewart
    0

    Hi Simon, instead of having AncestorOfSelf you can have it like this..

    var Node = @Model.NodeById(1030);
    @foreach (var page in Node.Children.Where("Visible"))

    Just change the NodeById Number to what the "our services" page is.. which you will find in the page properties. 

  • Paul Stewart 50 posts 71 karma points
    Mar 23, 2012 @ 14:24
    Paul Stewart
    0

    var Node = @Model.NodeById(1030);

    <ul>

    @foreach (var page in Node.Children.Where("Visible")) {

    <li><a href="@page.Url">@page.Name</a></li>

    }

    </ul>

    Sorry forgot to add rest of code...


  • Simon Bowler 14 posts 34 karma points
    Mar 23, 2012 @ 14:28
    Simon Bowler
    0

    Thanks Paul,

    That is that way I was doing it. BUt becasue we have language site, when you copied across the whole ourt services folder from the UK to say, German, the nav on german pages would display the uk nav, becasue of the hardcoded node id value.

    I have just signed up to get the videos and this worked for me.

    <ul id="servicesNav">
     
    @foreach (var page in @Model.Children) {
      <li><a href="@page.Url">@page.Name</a></li>
    }
    </ul>


    Thanks for your speedy responce, good to be part of a great communit.

    Simon

  • Simon Bowler 14 posts 34 karma points
    Mar 23, 2012 @ 14:29
    Simon Bowler
    0

    Thanks Paul,

    That is that way I was doing it. BUt becasue we have language site, when you copied across the whole ourt services folder from the UK to say, German, the nav on german pages would display the uk nav, becasue of the hardcoded node id value.

    I have just signed up to get the videos and this worked for me.

    <ul id="servicesNav">
     
    @foreach (var page in @Model.Children) {
      <li><a href="@page.Url">@page.Name</a></li>
    }
    </ul>


    Thanks for your speedy responce, good to be part of a great community.

    This issue is now closed, thanks

    Simon

  • Paul Stewart 50 posts 71 karma points
    Mar 23, 2012 @ 14:46
    Paul Stewart
    0

    Try this simon i would rename the main "homepages" like 

    "UK - Home" = "EN-GB"
    "DE - Home" = "DE-DE"  

    string url = Request.ServerVariables["SERVER_NAME"].ToString();

     

    if (url.ToLower().Contains("EN-GB"))

        {

     

    var Node = @Model.NodeById(1030);
    <ul>
    @foreach (var page in Node.Children.Where("Visible")) {
    <li><a href="@page.Url">@page.Name</a></li>
    }
    </ul>

     

    }

     

    if (url.ToLower().Contains("DE-DE"))

        {

     

    var Node = @Model.NodeById(1110);
    <ul>
    @foreach (var page in Node.Children.Where("Visible")) {
    <li><a href="@page.Url">@page.Name</a></li>
    }
    </ul>

     

    }

Please Sign in or register to post replies

Write your reply to:

Draft