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
    Apr 02, 2013 @ 14:42
    René Andersen
    0

    Show children from a specific Doctype

    Hi

    I need a list of children from a specific Doctype and i am thinking that i can use a "if" statement to solve the problem. But i have not been able to make it work. Is it wrong to use a "if" statement like this one below:

    if (page.NodeTypeAlias == "referencesRoot")

    If it is the way to do it where in the code below should i put this "if" statement to make it work proberly?

    @{ 
    @*Get the root of the website *@
    var root = Model.AncestorOrSelf(3);
    }
    @foreach (var group in Model.Children.InGroupsOf(4))
    {
    <div class="row">
    @foreach (var page in group)
    {
    <div class="span3">
    <div class="service-overview">
    <h5><span class="link-white"><a href="@page.Url">@page.headerMain</a></span></h5>
    <p>@(Library.Truncate(Library.StripHtml(page.mainText), 60, true))</p>
    <img src="@page.image" alt="" />
    <div class="service-overview-overlay">+</div>
    </div><!-- end .service-overview -->
    </div><!-- end .span3 -->
    }
    </div><!-- end .row -->
    <br />
    }

    Thanks in advance!

    //René

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 02, 2013 @ 15:28
    Fuji Kusaka
    0

    Hi Rene,

    You could either do something like

    @foreach(var group in Model.AncestorOrSelf(3).Descendants("docType")){
    }

    or

    @foreach(var group in Model.Children.Where("NodeTypeAlias == "\DocType"\")){
    }
  • René Andersen 238 posts 684 karma points
    Apr 02, 2013 @ 15:40
    René Andersen
    0

    Hi Fuji,

    Could you please try to put it in the code example that I posted, because I am a rookie in Razor. :-)

    I have tried to replace:

    @foreach(vargroupinModel.Children.InGroupsOf(4))

    With your examples but it tells me "Script error".

    Thank you!

    //René

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 02, 2013 @ 15:54
    Fuji Kusaka
    0

    Yes Could you please explain how you have your content set ?

     

  • René Andersen 238 posts 684 karma points
    Apr 02, 2013 @ 16:24
    René Andersen
    0

    Of course, here you are:


  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 02, 2013 @ 16:49
    Fuji Kusaka
    0
    @{
    <ul>
    @foreach(dynamic n in Model.AncestorOrSelf(1).Descendants("referencesRoot").Where("!umbracoNaviHide")){
       <li><a hrfe="@n.Url">@n.Name</a> // Here you should get the folder name "Arbejdsomrader"
    @if(n.Count()>0){ // Mmake some test to see if any children "Forside"
    <ul>
    @foreach(var page in n.Children.Where("Visible")){
    <li>@page.Name</li>
    }
    </ul>
    }
    </li>
    </ul>

    }

    Hope it helps

    //Fuji

     

  • René Andersen 238 posts 684 karma points
    Apr 02, 2013 @ 19:56
    René Andersen
    0

    Hi Fuji

    I did not manage to get it working but i found a new solution which is working for this project. Thank you for your time and help. :-)

    See my solution below:

    @{
    // Get root node:
    var root = Model.AncestorOrSelf();

    // Get all descendants, filter by type:
    var nodes = root.Descendants("ServiceSingleFrontpage");

    // Loop through the filtered nodes, displaying the properties:
    <div class="row">

    @foreach (var page in nodes)
    {
    <div class="span3">
    <div class="service-overview">
    <h5><span class="link-white"><a href="@page.Url">@page.headerMain</a></span></h5>
    <p>@(Library.Truncate(Library.StripHtml(page.mainText), 60, true))</p>
    <img src="@page.image" alt="" />
    </div><!-- end .service-overview -->
    </div><!-- end .span3 -->
    }
    </div>
    }

    //René

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 02, 2013 @ 20:00
    Fuji Kusaka
    0

    Hi Rene,

    Good you got it workin, just one thing you could do to save some line of code

    var nodes = Model.AncestorOrSelf().Descendants("ServiceSingleFrontPage");
  • René Andersen 238 posts 684 karma points
    Apr 02, 2013 @ 21:11
    René Andersen
    0

    Hi Fuji

    Thank you! Nice to clean up the code.

    //René

Please Sign in or register to post replies

Write your reply to:

Draft