Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 02, 2012 @ 12:42
    Fuji Kusaka
    0

    Jump to First Child in Navi

    Hi guys,

    Other than using the content picker in umbraco  can somehow explain how to point the url of the parent to the first child node instead?

    The idea would be by using a boolean, so if the admin want the url to point to the child he only checked it and if not i will use the actual path of the parent.

    I have the following in my razor file

     

    if (childPage.Children.Count() > 0 || childPage.Where("skip")){
           <ul>
              <li><a href="@childPage.Url.Down"><strong>@childPage.Name - </strong></a></li>
                    @foreach(var sub in childPage.Children){
                    <li><a href="@sub.Url">@sub.Name</a></li>
                      }
               </ul>                                   
    }       

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 02, 2012 @ 14:01
    Fuji Kusaka
    0

    Just for the record the property Alias "Skip" here is only to define a bold node if checked. My bad i didnt renamed it!

    Can something like this be use to get the url ?

    <a href="@childPage.Where("jump", "valueIfFalse", "valueIfTrue")">
  • Jamie Howarth 306 posts 773 karma points c-trib
    Aug 02, 2012 @ 14:35
    Jamie Howarth
    1

    Try this:

    @foreach (dynamic item in parentMenu) {
    string firstChildUrl = (item.Children.Count() > 0) ? item.Children.First().Url : item.Url;
    <a href="@firstChildUrl">item.Name</a>
    }

    This will use the URL of the first child, otherwise it will use the URL of the node itself if no children are present.

    Hope this helps,

    Benjamin

  • Jamie Howarth 306 posts 773 karma points c-trib
    Aug 02, 2012 @ 14:54
    Jamie Howarth
    0

    Fuji,

    Can you post up your existing XSLT please?

    Thanks,

    Benjamin

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 03, 2012 @ 07:57
    Fuji Kusaka
    0

    Hi Benjamin,

    Sorry for replying only now, was out of the office. Here is how my xslt looks like but am not trying to convert this xslt to razor. Am working on another project where the possibility of changing the Url of the parent to child node needs to be available.

    <xsl:choose>
         <xsl:when test="count(./*[@isDoc]) &gt; 1  and string(linkToSubpage) = '1'">
                 <xsl:value-of select="umbraco.library:NiceUrl(./*[@isDoc]/@id)" />
         </xsl:when>           
          <xsl:otherwise>
                   <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
            </xsl:otherwise>           
     </xsl:choose>
  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 03, 2012 @ 11:17
    Fuji Kusaka
    0

    Btw got it working here is the Razor File

    @if(page.Children.Count() > 0){
                            <ul>
                                 @foreach(dynamic childPage in page.Children.Where("Visible")){
                                     string ChildUrl = (childPage.Children.Count() > 0 && childPage.Where("jump")) ? childPage.Children.First().Url : childPage.Url;      
                                   if (childPage.Children.Count() > 0 || childPage.Where("skip"))
                                     {     
    <ul>
                                          <li><a href="@ChildUrl"><strong>@childPage.Name</strong></a></li>
                                           @foreach (dynamic sub in childPage.Children){ 
                <li><a href="@sub.Url">@sub.Name</a></li>
     }
                                         </ul>                                   
                                     }      
                                   else{
                                         <ul>
                                            <li>/*@childPage.Name</li>
                                         </ul>
                                     }    
                                  }                                                
                             </ul>
     }        

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft