Copied to clipboard

Flag this post as spam?

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


  • Michael 9 posts 89 karma points
    Feb 07, 2018 @ 19:30
    Michael
    0

    Reference Root Node URL in Multilingual Multisite

    I have a multilingual multisite that currently has two home nodes - one is named "Home" and lives at the root of the site "/" - the other is named "Home-DE" and lives at "/de/". I have a partial view for my header navigation that contains a logo for the site that links back to the home page. I have tried many solutions to link that logo to the "/de/" root when you are on the de site - but all I seem to be able to grab is root "/" so the logo always links to the English site. How do I reference the root of the node that my page is currently under?

    Here is my current code:

    @{
        UmbracoHelper rootHelper = new UmbracoHelper(UmbracoContext.Current);
        var root = rootHelper.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "Home");
        var rootUrl = root.Url;
    }
    

    and I am referencing it like this:

    <a class="navbar-brand header__logo" href="@rootUrl">
    
  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Feb 07, 2018 @ 20:49
    Alex Skrypnyk
    101

    Hi Michael

    Try this code:

    var rootUrl = Umbraco.AssignedContentItem.Site().Url;
    

    .Site - returns current root node.

    /Alex

  • Michael 9 posts 89 karma points
    Feb 07, 2018 @ 20:56
    Michael
    0

    Thank you, Alex! That did the trick - you are a life saver!

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Feb 07, 2018 @ 20:57
    Alex Skrypnyk
    0

    You are welcome, Michael, have a great day!

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft