Copied to clipboard

Flag this post as spam?

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


  • Maciek 6 posts 26 karma points
    Jan 08, 2014 @ 18:12
    Maciek
    0

    Finding the Url of the site's root ?

    Hi guys,

    First of all, I'm a total Umbraco newb, with some experince in MVC3+ and lots of .NET experience.

    Using one of the blog posts found on the web, I've created a partial navigation view :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @*
        Macro to display child pages below the root page of a standard website.
        Also highlights the current active page/section in the navigation with
        the css class "current".
    *@
     
    @{
        @*Get the root of the website *@
        var root = CurrentPage.AncestorOrSelf(1);
    //var rootNode = Model.Content.AncestorOrSelf(1).First();
    }
     <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              <a class="navbar-brand" href="@CurrentPage.FindRootNode().NiceUrl">Project name</a>
            </div>
            <div class="navbar-collapse collapse">
              <ul class="nav navbar-nav">
               @foreach (var page in root.Children.Where("Visible"))
               {
                 <li class="@(page.IsAncestorOrSelf(CurrentPage) ? "active" : null)">
                   <a href="@page.Url">@page.Name</a>
                 </li>
               }
              </ul>    
              <form class="navbar-form navbar-right" role="form">
                <div class="form-group">
                  <input type="text" placeholder="Email" class="form-control">
                </div>
                <div class="form-group">
                  <input type="password" placeholder="Password" class="form-control">
                </div>
                <button type="submit" class="btn btn-success">Sign in</button>
              </form>
            </div><!--/.navbar-collapse -->
          </div>
        </div>

    It's a pretty basic navigation bar, that's using Twitter Bootstrap. I'd like the "Project Name" (in bold) to point directly to the site's root url, but I have absolutely no idea how to do it.

    My site structure is like this :

    Home
     +----- Contact

     

    When I'm on the Contact page - the root url is : http://localhost:36184/contact/ - and I'm expecting it to be just : http://localhost:36184 . Please note that Home is set to be root via the umbraco's back-end (whatever it's name is ;) )

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Jan 08, 2014 @ 19:10
    Ali Sheikh Taheri
    0

    Hi Maciek,

    Is there any reason you want to find the URL of the root? because it is always just "/".

    this should give you the root url

    Model.Content.AncestorOrSelf(1).Url  // nice url is obsolete
    

    Cheers

    Ali

Please Sign in or register to post replies

Write your reply to:

Draft