Copied to clipboard

Flag this post as spam?

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


  • tarekahf 215 posts 153 karma points
    Jan 27, 2010 @ 15:52
    tarekahf
    0

    Inline xslt to get root node of multi-language web site.

    I have setup multi-language web site for the Runway module.

    The problem is that the Home Page in "Runway Master" is set to <a href="/">....</a> which will not work if the current node is under the second Language Content Node.

    So I decided to use my knowledge to find the root language node of the current node using in-line XSLT.

    This is what I did: 

        <a href=" <umbraco:Item field="pageID" runat="server" xslt="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById({0})/ancestor-or-self::node [@level='1' and string(data[@alias='language']) != '']/@id)"></umbraco:Item>">
        <umbraco:Item runat="server" field="siteName" recursive="true" />
        </a>

     

    The great thing is that it is working !

    But it looks a bit complicated.

    Do you have a better approach ?

    Tarek.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jan 27, 2010 @ 16:03
    Douglas Robar
    0

    If you're using domains then the "/" href would work perfectly.

    If you are using top level nodes for your sites then you'd want to do something exactly like what you've done, that's a great solution.

    To make the code shorter (but no more functional) you might add a new property on the homepage docType for 'siteUrl' and use a recursive umbraco:Item just like you did for the 'siteName'.

    But... since the result of this xslt is not going to change you would get a slight performance benefit by making an xslt macro for the entire <a> tag and then cache the macro with a large cache time. Be sure to set the check box for caching the macro by page since the output is different depending on which page of the site you're on.

    I'd make a short macro simply for the performance gain of caching the macro, but it isn't a big deal for such a simple macro so it is more in the category of optimization than necessity.

    cheers,
    doug.

     

Please Sign in or register to post replies

Write your reply to:

Draft