URL pathway is wrong - html

I'm working on a project were I want to add top links to the masterPage and each top-link to have its own navigation like this:
What I did was to include the top-links directly under the Content
The problem with this however, is that the URL pathway is wrong when selecting a menu under non-HomePage link
For example if I select For skolpersonal as a top-link and then select a menu and then a submenu, the URL pathway would be: menu/submenu
What I want it to be is: for-skolpersonal/menu/submenu
For some reason the URL "resets" every time I select a menu under a top-link.
MasterPage:
<header>
<div class="row col-md-12">
<nav class="entry-links">
<ul>
<li id="elever">
För elever
</li>
<li id="skolpersonal">
För skolpersonal
</li>
<li id="ungdom">
Ungdom och elevdatabas
</li>
</ul>
</nav>
</div>
<div class="row">
<div class="col-xs-8 col-sm-12 col-md-4">
<a href="#home.Url">
<div class="brand" style="background-image:url('#(home.SiteLogo)?height=100&width=700&')"></div>
</a>
</div>
</div>
<div class="row">
<div class="col-md-12 main-nav">
<nav id="cbp-hrmenu" class="meny cbp-hrmenu col-md-10 col-md-offset-1">
#{ Html.RenderPartial("MainNavigation"); }
</nav>
</div>
<br />
<br />
</div>
<div class="container-fluid">
<div class="container">
</div>
</div>
<div id="toggle" class="toggle">
<span></span>
</div>
</header>
MainNavigation:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{ var home = CurrentPage.Site(); }
#if (home.Children.Any())
{
#* Get the first page in the children *#
var naviLevel = home.Children.First().Level;
#* Add in level for a CSS hook *#
<div class="linje"></div>
<ul class="meny level-#naviLevel">
#* For each child page under the home node *#
#foreach (var childPage in home.Children)
{
if (childPage.Children.Any())
{
<li class="dropdown has-child #(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
#if (childPage.DocumentTypeAlias == "Huvudmeny")
{
<span>#childPage.Name</span>
#childPages(childPage.Children)
}
else
{
#childPage.Name
}
#helper childPages(dynamic pages)
{
#* Ensure that we have a collection of pages *#
if (pages.Any())
{
#* Get the first page in pages and get the level *#
var naviLevel = pages.First().Level;
#* Add in level for a CSS hook *#
<ul class="meny dropdown-menu sublevel level-#(naviLevel)">
#foreach (var page in pages)
{
<li>
#page.Name
#* if the current page has any children *#
#if (page.Children.Any())
{
#* Call our helper to display the children *#
#childPages(page.Children)
}
</li>
}
</ul>
}
}
</li>
}
else
{
<li class="#(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
#childPage.Name
</li>
}
}
</ul>
<div class="linje col-md-12" ></div>
}
Is there a way to make the URL pathway to go as I want them to? topmenu/menu/submenu
I'm using Umbraco.

To include top level nodes in the path go to your web.config file and change the value of the umbracoHideTopLevelNodeFromPath app setting from true to false.

Related

Bind child element position to parent element

I have a navigation that is horizontal. Under every choice I have a div that opens up on click. But the problem is that it binds it's position to the parent navigation button. I want every div that opens on the exact same spot. I want every child div that opens to open from the first element in the navigation bar.
So in this case i want the white open div to bind to "Nyheter" instead. I really can't solve it, I tried set a div element before the navigation that all div that opens binds to in css but it not seems to work.
<div class="Container">
<nav class="NavHorizontal Grid Grid--alignMiddle">
#Navigation.RenderNavigation("master/navigationDesignHeader.cshtml", navigationSettings)
</nav>
</div>
//NavigationDesignheader.cshtml under this line
var elementId = 1;
foreach (var node in nodes)
{
var idElement = "megaMenu" + elementId;
<div class="NavHorizontal-item Grid-cell u-sizeFit" id="#idElement">
<a class="Button Button--tab navigationHeaderLink u-pointer" onclick="toggleMenu('#elementId')">
#node.Name
</a>
#RenderMegaMenu(node.Nodes, node.Link, node.Name)
</div>
elementId++;
}
Megamenu:
<div>
<div id="megaMenuDropdown" class="Container megaMenuDropdown-content displayNone">
<div class="Grid Grid--withGutter">
<div class="Grid-cell u-sizefull u-mt-10">
#nodeName
<div class="megaMenuToggle-closeBars u-pointer" style="float:right">
<span class="megaMenuToggle-closeBar"></span>
<span class="megaMenuToggle-closeBar"></span>
</div>
</div>
</div>
<hr class="colorBlue" />
<div class="Grid Grid--withGutter">
<div class="Grid-cell u-size12of12 u-md-size6of12 u-lg-size6of12">
<ul>
#foreach (var node in firstColumn)
{
<li class="u-mb-10 linkHover">
<a class="userLink colorBlue" href="#node.Link">#node.Name</a>
</li>
}
</ul>
</div>
#if (moreThanTen)
{
<div class="Grid-cell u-size12of12 u-md-size6of12 u-lg-size6of12">
<ul>
#foreach (var node in secondColumn)
{
<li class="u-mb-10 linkHover">
<a class="userLink colorBlue" href="#node.Link">#node.Name</a>
</li>
}
</ul>
</div>
}
</div>
</div>
</div>
Any suggestions?

How to toggle accordion button from another page

I have an accordion menu in my website top page.
when click primary menus, accordion toggles using jQuery.
But when link to it from primary menus in another page, it doesn't work.
primary-menu
<ul id="menu-aaa" class="primary-menu">
<li id="menu-item-1">
home</li>
<li id="menu-item-2">
aaa</li>
<li id="menu-item-3">
bbb</li>
</ul>
accordion menu
<div id="aaa" class="testmenu">
<label for="testmenu_bar01"></label>
<input type="checkbox" id="testmenu_bar01" class="accordion">
<ul id="links01">
<li class="testmenu01-li-01">link1</li>
<li class="testmenu01-li-02">link2</li>
<li class="testmenu01-li-03">link3</li>
<li class="testmenu01-li-04">link4</li>
</ul>
</div>
<div id="bbb" class="testmenu">
<label for="testmenu_bar02"></label>
<input type="checkbox" id="testmenu_bar02" class="accordion">
<ul id="links02">
<li class="testmenu02-li-01">link1</li>
<li class="testmenu02-li-02">link1</li>
<li class="testmenu02-li-03">link1</li>
<li class="testmenu02-li-04">link1</li>
</ul>
</div>
jQuery
$(function($){
$("ul.primary-menu > li.menu-item-2 > a").click(function() {
$('input#testmenu_bar01').prop('checked',true);
})
$("ul.primary-menu > li.menu-item-3 > a").click(function() {
$('input#testmenu_bar02').prop('checked',true);
$('li.testmenu01-li-02').css('margin-top','2vh');
})
});
I read this
How open my toggle-accordion from another page?
and I tried to add
$(location.hash).find(.accordion).prop('checked', true);
to my cord, but it was wrong.
Then, I tried this (in my wordpress site)
jQuery(function($){
var url = $(window.location.href);
var hash = url.substring(url.indexOf('#'));
$(hash).find('input[type=checkbox]').prop('checked', true);
});
But it was something wrong, it doesn't work.
I solved the problem by use this jQuery code;
$(location.hash).find('input[type=checkbox]').prop('checked', true);
Thank you.

HTML Tabs that are created using foreach

Im working on a a web page that has to have tabs. The tabs have to be created using a for each because the content has to be loaded out of a list. I found a tutorial on w3schools (https://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp). I tried to replicate on of the examples and added the foreach loop. But if i click one of the tabs, i get sent to the index.hmtl (probably because of the # in the href).I can neither change the model or the list.
<div class="container">
<ul class="nav nav-tabs">
#foreach (FooModel foo in fooModels)
{
<li class="nav-item">
<a class="nav-link active" href="#foo_#foo.Id">#foo.Title</a>
</li>
}
</ul>
</div>
<div class="card-body">
<h3>foo's</h3>
<div class="tab-content">
#foreach (FooModel fooModel in fooModels)
{
<div id="application_#fooModel.Id" class="tab-pane fade">
<h3>Foo:: #fooModel.Title</h3>
#if (IsInEditMode == true)
{
<InputDate #bind-Value="fooModel.DateFrom"></InputDate>
<InputDate #bind-Value="fooModel.DateTo"></InputDate>
}
else
{
<p>#fooModel.DateFrom.ToString()</p>
<p>#fooModel.DateTo.ToString()</p>
}
</div>
}
</div>
</div>
You forgot to include data-toggle="tab" inside <a class="nav-link active" href="#foo_#foo.Id">#foo.Title</a>. You then also need to remove the active inside it because it is inside a foreach loop. It should work if you add it.

ASP.Net Hide Left Hand Menu On Home Page

I have an asp.net website which is having a left hand menu added to it and have hit an issue as I have found that I am doing a lot of code duplication (which is bad I know). What I want is for the left hand menu to be added to my Site.Master file rather than me having to add it to every single page.
I can do this, but the left hand menu is then displayed on the "Home" page which I don't want so i was thinking that i need some sort of IF statement but I don't know how I can do this as I cant look at the URL as when the user hits the page its the standard naming (e.g. http://www.webaddress.co.uk/)
My left hand menu is a scrolling nav-stacked which is working fine so I will also need to add the JQuery for this to the Site.Master I think.
Current HTML for my 'About Us' page
<asp:Content ID="AboutBodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="col-sm-3 hidden-xs" style="padding-left: 0px">
<div class="follow-scroll">
<ul class="nav nav-stacked">
<li><a runat="server" href="~/">Home</a></li>
<li class="active"><a runat="server" href="~/About">About</a></li>
<li><a runat="server" href="~/Session/pg1">Session</a></li>
<li><a runat="server" href="~/EmailPg">Email</a></li>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-9">
<h2><%: Title %>.</h2>
<p>Use this area to provide additional information.</p>
<p>Use this area to provide additional information.</p>
<p>Use this area to provide additional information.</p>
</div>
<script type="text/javascript">
(function ($) {
var element = $('.follow-scroll'),
originalY = element.offset().top;
// Space between element and top of screen (when scrolling)
var topMargin = 75;
// Should probably be set in CSS; but here just for emphasis
element.css('position', 'relative');
$(window).on('scroll', function (event) {
var scrollTop = $(window).scrollTop();
element.stop(false, false).animate({
top: scrollTop < originalY
? 0
: scrollTop - originalY + topMargin
}, 300);
});
})(jQuery);
</script>
</asp:Content>
The HTML code below is what I thought of for my Site.Master but as I said it needs to not be displayed on the "Home Page".
<div class="container body-content" style="padding-top: 25px">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="col-sm-3 hidden-xs" style="padding-left: 0px">
<!-- 'IF' statement to go here so not displayed on Home page -->
<ul class="nav nav-stacked">
<li><a runat="server" href="~/">Home</a></li>
<li style="border-left: 1px solid lightgray"><a runat="server" href="~/About">About</a></li>
<li style="border-left: 1px solid lightgray"><a runat="server" href="~/Session/pg1">Session</a></li>
<li style="border-left: 1px solid lightgray"><a runat="server" href="~/EmailPg">Email</a></li>
</ul>
</div>
<div class="col-xs-12 col-sm-9" style="padding-right: 0px">
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</div>
</div>
</div>
</div>
</div>
To solve all the issues, I added an ID and a runat="server" to the container for the menu, and then I could access it in the code behind:
div class="follow-scroll">
<div ID="Sidebar" runat="server" class="col-sm-3 hidden-xs" style="padding-left: 0px">
<ul class="nav nav-stacked">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/About">About</a></li>
<li><a runat="server" href="~/Session/pg1">Session</a></li>
<li><a runat="server" href="~/EmailPg">Email</a></li>
</ul>
</div>
</div>
Then, in the codebehind for the master page, I can do something like:
C#:
protected void Page_Load(object sender, EventArgs e)
{
var URL = Request.Url.PathAndQuery;
if(URL == "/default" || URL == "/default.aspx")
{
this.Sidebar.Visible = false;
}
}
This uses PathAndQuery from the HttpContext.Request.Url property, which is a Uri object.
Then I was able to move my JQuery to my site.master file also

show different images after click on different li (as a second menu)

This is my html as a second menu in a page.
<ul class="nav-tabs text-center" role="tablist">
<li class="active">Lunch</li>
<li class="diner">Diner</li>
<li class="pannenkoek">Pannenkoek</li>
<li class="borrel">Borrel</li>
</ul>
Now when i want to click on a li there has to show an image. When you click on the second link there has to show another image. The problem now is when i click on a link, it doesn't matter which one, it shows al the images on the page of all the divs.
<div class="active"><img src="images/themenu/lunchkaart-november.jpg" alt="lunchkaart" /> </div>
<div class="diner"><img src="images/themenu/dinerkaart-januari.jpg" alt="dinerkaart" /> </div>
How te create when click on li lunch, it show image lunch.
When click on li diner, it show image diner.
What did i do wrong?
You need jQuery for that. Use this or maybe add class active for clicked element div. Also active class most be display:block or display:inline-block;
<ul class="nav-tabs text-center" role="tablist">
<li class="lunch">Lunch</li>
<li class="diner">Diner</li>
<li class="pannenkoek">Pannenkoek</li>
<li class="borrel">Borrel</li>
</ul>
<div class="content">
<div class="lunch" style="display:none"><img src="images/themenu/lunchkaart-november.jpg" alt="lunchkaart" /> </div>
<div class="diner" style="display:none"><img src="images/themenu/dinerkaart-januari.jpg" alt="dinerkaart" /> </div>
</div>
jQuery(document).ready(function(){
jQuery('.nav-tabs li').click(function(){
var elementClass = jQuery(this).attr("class").toString();
console.log(elementClass);
jQuery('.content div').hide();
jQuery('.'+elementClass,'.content').show();
});
});
http://jsfiddle.net/e79g4p1p/14/