Copied to clipboard

Flag this post as spam?

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


  • Michael 63 posts 211 karma points
    Oct 14, 2014 @ 13:46
    Michael
    0

    Logo with link to homepage on each language version

    Hi guys

    I have an old XSLT file that I would like to convert to razor. The file gets the homepage node and links to it.

    My site structure looks like this:

    Homepage

    --Subpage

    Language version

    --Homepage

    ----Subversion

    My working XSLT looks like this:

    <xsl:for-each select="$currentPage/ancestor-or-self::Homepage">
      <a href="{umbraco.library:NiceUrl(@id)}"><img src="/Media/images/logo.png" alt="Logo" /></a>
    </xsl:for-each>

    I thought the razor would work with this:

    @foreach (var homePage in CurrentPage.AncestorOrSelf().Homepage.Where("Visible"))
    {
      <a href="@homePage.Url"><img src="/Media/images/logo.png" alt="Logo" /></a>
    }

    But no luck so far. Any pointers to why it's not working ? :)

     

    /Michael

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 14, 2014 @ 13:48
    Dennis Aaen
    0

    Hi Michael,

    What if you are doing something like this:

    @foreach(var homePage in CurrentPage.AncestorOrSelf("Homepage").Where("Visible"))
    {
     
    <a href="@homePage.Url"><img src="/Media/images/logo.png" alt="Logo"/>a>
    }

    Hope this helps,

    /Dennis

  • Michael 63 posts 211 karma points
    Oct 14, 2014 @ 13:56
    Michael
    0

    Hi Dennis

    Thank you for a very quick reply. When I try your way I get an error.

     

    /Michael

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 14, 2014 @ 14:05
    Dennis Aaen
    1

    Hi Michael,

    Okay what if you are doing something like this:

    @foreach(var homePage in CurrentPage.AncestorOrSelf(1).Descendants("Homepage").Where("Visible"))
    {
     
    <a href="@homePage.Url"><img src="/Media/images/logo.png" alt="Logo"/>a>
    }

    Hope this helps,

    /Dennis


  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 14, 2014 @ 14:12
    Dennis Aaen
    0

    Hi Michael

    Or maybe you could try something like this:

    @foreach (var homePage in Umbraco.ContentAtRoot().Descendants("Homepage").Where("Visible")) { 
    <a href="@homePage.Url"><img src="/Media/images/logo.png" alt="Logo"/>a>
    }

    Hope this helps,

    /Dennis

  • Michael 63 posts 211 karma points
    Oct 14, 2014 @ 14:12
    Michael
    0

    Some of the way now :)

    I now get the image displayed on my language version, but not on the org. language

    Homepage - No image

    --Subpage - No image

    Language version

    --Homepage - Image

    ----Subversion - Image

    I guess its a level thing with the 1 in .AncestorOrSelf() ?

    /Michael

  • Michael 63 posts 211 karma points
    Oct 14, 2014 @ 14:14
    Michael
    0

    That last one gives me an error.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 14, 2014 @ 15:33
    Dennis Aaen
    1

    Hi Michael,

    I assueme that you are using the same templates and document types to each site. Maybe you need to re-think your site struture to get this work.

    If it was me that should bulid a structure like yours I would do it like this:

    Content (Umbraco Content)
    --Site1(Homepage)
    ---Subpage
    ----Subpage
    --Site2(Homepage)
    ---Subpage
    ----Subpage
    --Site3(Homepage)
    ---Subpage
    ----Subpage

    And maybe it´s more easy to find some Razor code that do what you need.

    Hope this helps,

    /Dennis

  • Michael 63 posts 211 karma points
    Oct 15, 2014 @ 08:07
    Michael
    0

    Hi again Dennis

    I guess you are right about a re-think. This way just overcomplicate things. The only reason why I build it this way was to get for instance a www.mysite.dk/en/sompage in the url.  But a re-think would mean that all the code I already have works.

    Thank you very much for your time, effort and pointers.  :)

    /Michael

Please Sign in or register to post replies

Write your reply to:

Draft