Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    Aug 30, 2010 @ 18:58
    Connie DeCinko
    0

    Conditional CSS in Master Template

    In my base template I need to change the CSS class based upon the node's level.  For instance, for pages that are one level deep, I want this:

    <div id="main" class="inner3">

    and for all other levels, I want this:

    <div id="main" class="inner2">

     

    Without using XSLT and a macro, is there a simple way to accomplish this?

     

  • Jamie Howarth 306 posts 773 karma points c-trib
    Aug 30, 2010 @ 19:04
    Jamie Howarth
    0

    Hi Connie,

    Yes you can do this, but it's not the easiest of methods and would involve two master templates.

    You'd use a Document_New event handler which would then detect the document's level and assign the template programmatically - something like:

    void Document_New(Document sender, NewEventArgs e) {
    sender.Template = (sender.Level == 1) ? myFirstTemplateID : mySecondTemplateID;
    }

    Best,

    Benjamin

  • Connie DeCinko 931 posts 1160 karma points
    Aug 30, 2010 @ 19:10
    Connie DeCinko
    1

    Bummer.  So, it sounds like an XSLT macro would actually be easier.  Determine the level, set the class name as a text string which drops into the template.

     

  • Hendrik Jan 71 posts 137 karma points
    Aug 30, 2010 @ 21:16
    Hendrik Jan
    0
    Hey Connie,
    This should do the trick:
    <div id="main" <umbraco:Item field="pageName" xslt="concat('class=&quot;inner', $currentPage/@level, '&quot;')" runat="server"></umbraco:Item>>
     
    </div>
    Regards,
    Niels
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 31, 2010 @ 12:41
    Ismail Mayat
    0

    Connie,

    Another way round it would be to make use of http://our.umbraco.org/projects/backoffice-extensions/cogworks-cogcsspickerdatatype then to your master doctype (if you have one or doctype you are working with) add a datatype of type cogcsspicker.  Then create css files for your levels with that definition and assign the css to your documents then update the template to pick that css up. Bit more work but no need for code.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft