Copied to clipboard

Flag this post as spam?

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


  • Ravindra 46 posts 117 karma points
    Aug 04, 2014 @ 12:03
    Ravindra
    0

    Navigation with different classes

    Hii all,

    I am Ravindra...

    I have a Master page with 4 child pages..i used a navigation in my master..i.e

    @{   

       var homePage = CurrentPage.AncestorsOrSelf(1).First();

         var menuItems = homePage.Children.Where("UmbracoNaviHide == false");

    }

    @foreach(var item in menuItems){                                

                <li class="li2"><a href="@item.Url">@item.Name</a></li>

     

    }

    but i have 4 different classes i.e li1,li2,li3,li4....and i need first child should get class li1 and second child li2 respectively ...i tried alot but can't get the answer please help me!

    Regards...

    Ravindra

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 04, 2014 @ 12:10
    Jeavon Leopold
    100

    Hi Ravindra,

    How about this:

    @{
        var homePage = CurrentPage.AncestorOrSelf(1);
        var menuItems = homePage.Children.Where("Visible");        
    }
    
    @foreach (var item in menuItems.ToContentSet())
    {
        var position = string.Format("li{0}", item.Position() + 1);        
        <li class="@position"><a href="@item.Url">@item.Name</a></li>
    }
    

    Jeavon

  • Ravindra 46 posts 117 karma points
    Aug 04, 2014 @ 12:33
    Ravindra
    0

    Thank u very much jeavon!

    let me check it

     

    Regards...

    Ravindra

  • Ravindra 46 posts 117 karma points
    Aug 05, 2014 @ 08:00
    Ravindra
    0

    Thank you very much jeavon!

    it's working!

    Regards,

    Ravindra....

  • Ravindra 46 posts 117 karma points
    Aug 06, 2014 @ 11:15
    Ravindra
    0

    HIii...i have 6 pages in my site...

    i want to apply a class for first 4 pages like li1 for page 1 and li2 for page 2 respectively ...rest of the 2 pages must have diffierent class and first for page 5 and last for page 6...

    i have tried the following code

    @{
       
    var homePage =CurrentPage.AncestorOrSelf(1);
       
    var menuItems = homePage.Children.Where("Visible");        
    }

    @foreach(var item in menuItems.ToContentSet())
    {
       
    var position =string.Format("li{0}", item.Position()+1);        
       
    <li class="@position"><a href="@item.Url">@item.Name</a></li>
    }
    please help me!
    Regards
    Ravindra
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 06, 2014 @ 12:42
    Jeavon Leopold
    0

    Something like this (change to your needs)

    @{
        var homePage = CurrentPage.AncestorOrSelf(1);
        var menuItems = homePage.Children.Where("Visible");
    }
    
    @foreach (var item in menuItems.ToContentSet())
    {
    
        var suffix = string.Empty;
        if (item.Position() <= 4)
        {
            suffix = (item.Position() + 1).ToString();
        }
        else if (item.Position() == 4)
        {
            suffix = "100";
        }
        else if (item.Position() == 5)
        {
            suffix = "300";
        }
        else
        {
            //if non of the above match
            suffix = "1000";
        }
    
        var liClass = string.Format("li{0}",  suffix);
    
        <li class="@liClass"><a href="@item.Url">@item.Name</a></li>
    }
    
  • Ravindra 46 posts 117 karma points
    Aug 06, 2014 @ 13:04
    Ravindra
    0

    Thanks jeavon!

     

    its working

    Regards,

    Ravindra..

Please Sign in or register to post replies

Write your reply to:

Draft