Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    Jan 12, 2015 @ 16:46
    Tony Groome
    0

    How can I access the children of another template

    Hi All

    I am trying to access the children of another template and can't. What I mean is: there are a few templates at level 2 - they are all under the Master. One is called CEO and under this the monthly reports from the CEO are written. There is another called Old Reports where we want a full list of all the reports written by the CEO. I have tried this:

    <div class="column w300 gut10">
           
    @foreach(var page in CurrentPage.Parent.Children)
    {
        HtmlString pain = new HtmlString("");
        foreach(var apage in page.Children)
        {
                                   
                   pain=  @apage.summary;
       
           
        }
       
       
               
        <div class="box">
             <div class="section">
                        <span style="line-height: 1.4em; font-size: 16px; font-weight: bold;">@page.Name</span>
             </div>
                   
                    <div class="section">
                        <p>@page.CEOContent</p>
                        <p><a class="buttonGrey block w130" target="_blank" [email protected] rel="nofollow">
                        @page.Name
                        <span class="arrow">></span>
                        </a>
                           
                        </p>
                    </div>
        </div>
        }
           


    </div>

    This is giving me a list of all the Level 2 pages. The CEO's reports are one level below them.

    Hope this makes sense.....

    Thanks

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 12, 2015 @ 17:01
    Jeavon Leopold
    1

    Hi Tony,

    If all of the CEO reports are of a unique document type then you can do something like this:

    foreach (var page in CurrentPage.Descendants().Where("DocumentTypeAlias  == \"myCEODocType\""))
    

    The document type alias is "myCEODocType"

    Jeavon

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 12, 2015 @ 17:15
    Jeavon Leopold
    1

    Hi Tony,

    Edited the above as it seems the magic pluraliser is not working in this context.

    Jeavon

  • Tony Groome 261 posts 804 karma points
    Jan 12, 2015 @ 17:48
    Tony Groome
    0

    Hi Jeavon

    Thanks, but no joy. I'm just getting a blank page. At least it's not falling over!

    I'll try again tomorrow, been at this way too long now!

    Thanks.

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 12, 2015 @ 17:55
    Jeavon Leopold
    0

    Hi Tony,

    Maybe try the below, it will make sure it's always getting nodes from the whole current tree.

    foreach (var page in CurrentPage.AncestorOrSelf(1).Descendants().Where("DocumentTypeAlias  == \"myCEODocType\""))
    

    Jeavon

  • Tony Groome 261 posts 804 karma points
    Jan 13, 2015 @ 11:59
    Tony Groome
    0

    Hi Jeavon

    After leaving it for the night I came up with this:

    @foreach(var page in CurrentPage.AncestorOrSelf(1).Children)
    {
       
       
        foreach(var apage in page.Children)
        {
            <p>@apage.Name</p>
               
               
        }
                   
                   
         
        }
            It almost works, I'm getting a list of the grandchildren's names. So I need a specific set, the CEO's. I can't figure out how to use the .Where as when I do it all goes blank!

    So close, no cigar....yet!

    Thanks.

    Tony

  • Tony Groome 261 posts 804 karma points
    Jan 13, 2015 @ 12:39
    Tony Groome
    100

    Hi Jeavon

    Got it

           
    @foreach(var page in CurrentPage.AncestorOrSelf(1).Children.Where("DocumentTypeAlias  == \"ceoAlias\""))
    {
       
       
        foreach(var apage in page.Children)
        {
           
            <p>@apage.Name</p>   
               
        }
                   
                   
         
        }
           
    That was pretty epic!

    Thanks for your help.

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 13, 2015 @ 17:48
    Jeavon Leopold
    1

    Great you got it!

Please Sign in or register to post replies

Write your reply to:

Draft