Copied to clipboard

Flag this post as spam?

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


  • Garry Bain 149 posts 124 karma points
    Mar 04, 2009 @ 17:33
    Garry Bain
    0

    Current page css class

    Hi guys,

    I currently have a "hard coded" menu on my site, hence there is no XSLT related to this menu (it had to be this way due to the design and custom classes associated with the navigation).

    But I need to add a ".current" class onto the nav item which refers to which page I am currently viewing. For example, when Im on my home page, then nav bar will generate this:

    [code]


    • Home

    • Contact

    • etc...
      [/code]

      Is there anyway to do this? Any help would be great.

      Cheers, Garry.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 04, 2009 @ 17:47
    Peter Dijksterhuis
    0

    Garry,

    depending on the hardcoded menu and your page-structure, you could use jquery to add a class to your li.
    But that all depends whether you can determine a link between the page and the menu. If your menu is hardcoded, I doubt it is easy to accomplish...

    There is no way you can build the menu using xslt? From the example you posted, it looks completely possible to me.

    HTH,
    PeterD

  • Garry Bain 149 posts 124 karma points
    Mar 04, 2009 @ 17:56
    Garry Bain
    0

    Hi Peter,

    I suppose I could do this, if the XSLT could just simply display similar HTML to what I posted above. I'm new to umbraco and xslt so I'm not really sure how to do basic stuff, I've just sort of followed the tutorials on umbraco.tv! Can I just create an XSLT macro that contains simple HTML and then insert a macro?

    Thanks for the swift reply!

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 04, 2009 @ 18:05
    Peter Dijksterhuis
    0

    Yes, you can use xslt to create a nice menu like you 'hardcoded'.
    If you use xslt, your menu will automagically be extended if a user adds a new page to the site. If you hardcode your menu, it won't.

    To have a play, go to the developer-section and create a new xslt. Instead of a 'clean' file, take a look at all the other examples you can use.
    You then insert that macro in a template and voila, the html that is created by the xslt will be shown.

    Hope this helps a bit more and if you have more questions, just ask!

    Cheers,
    PeterD

  • Garry Bain 149 posts 124 karma points
    Mar 04, 2009 @ 18:11
    Garry Bain
    0

    The point of this hard coded is menu, is that new pages don't get added on when created - due to the nature of the site - it has a specific amount of pages and we dont want menus adding on - so is it possible to actually just enter the html for the nav items I already for example:

    [code]



    • Home

    • About

    • Contact





    [/code]

    This would be the xslt file with hard coded items in. Then I insert the macro in the template. If I did it this way - would I still be able to associate the page with the nav item itself - in order to add the .current class?

    Apologies - I know this is a silly way of doin a nav - but it's the nature of the site!

    Garry.

  • Petr Snobelt 923 posts 1535 karma points
    Mar 04, 2009 @ 18:22
    Petr Snobelt
    0

    You can modify your xslt like this, but it is far from ideal :-)


  • Home

  • About


  • Petr

Copy Link
  • Garry Bain 149 posts 124 karma points
    Mar 05, 2009 @ 10:17
    Garry Bain
    0

    Thats Petr, thats exactly what I needed - thanks very much.

    Copy Link
  • Petr Snobelt 923 posts 1535 karma points
    Mar 05, 2009 @ 18:08
    Petr Snobelt
    0

    I'm glad it works :-).

    Petr

    Copy Link
  • Please Sign in or register to post replies

    Write your reply to:

    Draft