Copied to clipboard

Flag this post as spam?

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


  • Niels 63 posts 119 karma points
    Jul 27, 2011 @ 14:13
    Niels
    0

    Select css by nodename with multiple websites

    Good day,

    I'm very busy with a project that haves multiple websites in one umbraco setup, but I have a little problem with the following thing. 

    I want to use one master-template and therefore I only want to change the source of the css file dynamically/appendable on the sitename or nodename from the website. Now I have created the following XSLT and it works on the homepage, but when I select a childnode it will load no style.

    Now I know with my xslt's it always select the nodename of the current node, but I want to select the website/root node. 

    I'm a newbie in Umbraco and xslt, so please go easy on me ;-) and please help me on this one.

      <xsl:for-each select="currentPage">
        <link rel="stylesheet" type="text/css" href="/css/{@nodeName}.css"/>
      </xsl:for-each>

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 27, 2011 @ 14:21
    Fuji Kusaka
    0

    Hi Niels,

    Are you planning on changing the css style through the backend? I did something alike by using dataType where the client can change the colorscheme of its homepage with predefine style.

    If you want something like that let me know.

    //fuji

  • Niels 63 posts 119 karma points
    Jul 27, 2011 @ 14:32
    Niels
    0

    @Fuji 

    That's not necessary because every new website that will be created, must have it's own colors/colorscheme that's not the same as the others and not only the colors will be different, but also the layout.

    But thank you very much for your input.

  • Medjeti 75 posts 126 karma points
    Jul 27, 2011 @ 15:06
    Medjeti
    0

    Hey Niels,

    This should work:

    <xsl:variable name="frontpage" select="$currentPage /ancestor-or-self::Frontpage" />
    <link rel="stylesheet" type="text/css" href="/css/{$frontpage /@nodeName}.css"/>

    - assuming all pages in your website are descendants of your frontpage. Substitute "Frontpage" in the first line with the nodeTypeAlias of your frontpage / root node.

     

  • Niels 63 posts 119 karma points
    Jul 27, 2011 @ 15:38
    Niels
    0

    Hey Medjeti,

    Thanks for your reply, but I tried it. But i'm not sure what you mean with nodeTypeAlias. When I use your solution and change 'frontpage' in the rootname. I get in the browser the following code:

    <link href="/css/.css" type="text/css" rel="stylesheet">

    So there is no filename defined before .css

    My projects structure is like this:

    Content
    |_Website 1
       |_Page/Childnode 1
       |_Page/Childnode 2
       |_Page/Childnode 3
       |_Page/Childnode 4
     |_Website 2
       |_Page/Childnode 1
       |_Page/Childnode 2
       |_Page/Childnode 3
       |_Page/Childnode 4
     |_Website 3
       |_Page/Childnode 1
       |_Page/Childnode 2
       |_Page/Childnode 3
       |_Page/Childnode 4  

  • Medjeti 75 posts 126 karma points
    Jul 27, 2011 @ 15:46
    Medjeti
    0

    The NodeTypeAlias is the Alias property of a given Document Type (you can see this value on the DocType's configuration page in the Settings section).

    In your case this will be the DocType of your website root nodes (Website 1, Website 2 etc.).

    So, if your DocType has an alias of "WebsiteRootPage", the code would be:

    <xsl:variablename="frontpage"select="$currentPage /ancestor-or-self::WebsiteRootPage"/>
    <linkrel="stylesheet"type="text/css"href="/css/{$frontpage /@nodeName}.css"/>
  • Niels 63 posts 119 karma points
    Jul 27, 2011 @ 15:53
    Niels
    0

    Yes! Your the hero of the day, feel myself pretty stupid, but learning in progress! Thank you very much!

  • Medjeti 75 posts 126 karma points
    Jul 27, 2011 @ 16:40
    Medjeti
    0

    Any time :o)

Please Sign in or register to post replies

Write your reply to:

Draft