Dropdown menu Umbraco - html

I made a menu for umbraco but I can't get the dropdown to work! Below is my code:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<div class="NavDigiCampuz">
<div>
<div class="nav nav-list tree">
#{
var documentRootNodeId = Model.Content.GetPropertyValue("documentRoot", true); // Fetch recursive document root id.
var selection = Umbraco.TypedContent(documentRootNodeId).Children.Where("Visible"); // Select all nodes below the document root.
}
#foreach(var item in Model.Content.Ancestor(1).Descendants("menu")){
foreach (var Menus in #item.Descendants("menuItem")){
<li class="MenuItems">#Menus.Name</li>
foreach (var MenuItems in #Menus.Children){
if(MenuItems.GetPropertyValue("hoofdstukIcoon") != "") {
<li><a class="NormalA" href="#MenuItems.Url"><i class="fa fa-#(MenuItems.GetPropertyValue("hoofdstukIcoon")) fa-fw"></i> #MenuItems.Name</a></li>
}else {
<li><a class="NormalA"href="#MenuItems.Url">#MenuItems.Name</a></li>
var childIsActive = false;
foreach(var sub in #MenuItems.Children){
if (CurrentPage.Url == sub.Url) {
childIsActive = true;
}
<ul class="nav subnav nav-list tree #(childIsActive ? "" : "collapse")">
#foreach(var sub2 in #MenuItems.Children){
<li #(CurrentPage.Url == sub.Url ? "class=active" : "")>
<a onclick="parent.resizeParent();" href="#sub.Url">#(sub.GetPropertyValue("hoofdstukMenuTitel") != "" ? sub.GetPropertyValue("hoofdstukMenuTitel") : sub.GetPropertyValue("hoofdstukTitel"))</a>
</li>
}
</ul>
}
}
}
}
}
</ul>
</div>
</div>
</div>
The dropdown code should start at <ul class="nav subnav nav-list tree #(childIsActive ? "" : "collapse")"> but that doesn't seem to work.
Below is a quick structure of how I want my page to be:
Help item 3 should have a dropdown which it doesn't have right now. What am I missing?

You have some inconsistencies in your structure:
this line:
<div class="nav nav-list tree">
should be this:
<ul class="nav nav-list tree">
And I would remove the <div> that wrapps it.
I'm just guessing you are using something like bootstrap, are you using a framework or custom css?
Your submenu should also be nested in the <li> element:
else
{
<li><a class="NormalA" href="#MenuItems.Url">#MenuItems.Name</a>
var childIsActive = false;
foreach (var sub in #MenuItems.Children)
{
if (CurrentPage.Url == sub.Url)
{
childIsActive = true;
}
<ul class="nav subnav nav-list tree #(childIsActive ? "" : "collapse")">
#foreach (var sub2 in #MenuItems.Children)
{
<li #(CurrentPage.Url == sub.Url ? "class=active" : "")>
<a onclick="parent.resizeParent();" href="#sub.Url">#(sub.GetPropertyValue("hoofdstukMenuTitel") != "" ? sub.GetPropertyValue("hoofdstukMenuTitel") : sub.GetPropertyValue("hoofdstukTitel"))</a>
</li>
}
</ul>
}
</li>
}

Related

Remove selected option from Angular select box in ng-repeat for next index

I am working on drop down in angular js which is already in ng-repat option.
I want to make it work in a way that when an option is selected in any of repeated select box it should not be available in other repeated select boxes.
My current code looks like this. :
HTML:
<div ng-repeat="endDate in endDate_counts">
<div class="sch_endDate_opsAmount_cell cell1">
<strong class="nc_Camaignfinance_title">Option</strong>
<div class="nc_Camaign_costFinance_opsSlct" select-input>
<div class="nc_Camaign_costFinance_opsSlct_inn">
<span>{{endDate.select_endDate}}</span>
<ul>
<li ng-click="endDate.select_endDate = 'Never'">
<em>Never</em></li>
<li ng-click="endDate.select_endDate = 'Impressions'">
<em>Impressions</em></li>
<li ng-click="endDate.select_endDate = 'Budget'">
<em>Budget</em></li>
<li ng-click="endDate.select_endDate = 'Clicks'">
<em>Clicks</em></li>
<li ng-click="endDate.select_endDate = 'Date'">
<em>Date</em></li>
</ul>
</div>
</div>
</div>
</div>
*Note: Please ignore the custom directives or other methods. I am using them myself and aware of them .
try:
html:
<ul>
<li ng-show="checkExist(key-1,'Never')" ng-click="endDate.select_endDate = 'Never'">
<em>Never</em></li>
<li ng-show="checkExist(key-1,'Impressions')" ng-click="endDate.select_endDate = 'Impressions'">
<em>Impressions</em></li>
<li ng-show="checkExist(key-1,'Budget')" ng-click="endDate.select_endDate = 'Budget'">
<em>Budget</em></li>
<li ng-show="checkExist(key-1,'Clicks')" ng-click="endDate.select_endDate = 'Clicks'">
<em>Clicks</em></li>
<li ng-show="checkExist(key-1,'Date')" ng-click="endDate.select_endDate = 'Date'">
<em>Date</em></li>
add this function in your js file:
$scope.checkExist = function(index,value){
if(index < 0){
return true;
}
if($scope.endDate_counts[index].select_endDate == value){
return false;
}else {
return true;
}
}

Changing the Values in an Unordered List <ul> using ng-repeat; also set an active <li>

I have been trying to work out how to produce a list, where if you click on one of the objects in the list, it becomes active. I have managed to get it working in the non-dynamic version of the code with ease. However, working on AngularJS dynamic version, I just can't seem to get it to work. The data is ok, so it can't be data related, it has to be my dynamic code that is not working.
This is a working piece of code (however not dynamic)
<ul class="nav nav-pills" ng-init="catVal = 1">
<li ng-class="{active: catVal===1}">
Category 1
</li>
<li ng-class="{active: catVal===2}">
Category 2
</li>
<li ng-class="{active: catVal===3}">
Category 3
</li>
</ul>
Now What I really want is an AngularJS dynamic version of this code. This is what I have tried and failed so far.
<ul class="nav nav-pills">
<li ng-repeat="category in model" ng-init="catVal = 1" ng-class="active: catVal === category.catID ">
{{category.catName}}
</li>
</ul>
The catID is associated with the category and should give the same results as the previous list. I get the names in the correct place, just the value is not working.
try this.
var app = angular.module("app",[]);
app.controller("ctrl" , function($scope){
$scope.rowIndex = -1;
$scope.items = [{"name":"ali","score":2},{"name":"reza","score":4},{"name":"amir","score":5},{"name":"asd","score":10}];
$scope.selectRow = function(index){
if(index == $scope.rowIndex)
$scope.rowIndex = -1;
else
$scope.rowIndex = index;
}
});
.active{
background-color:#a11af0;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl" class="panel-group" id="accordion">
<ul class="nav nav-pills" ng-init="catVal = 1">
<li ng-repeat="item in items" ng-class="{'active':rowIndex == $index }" ng-click="selectRow($index)">
{{item.name}}
</li>
</ul>
</div>

how to dynamically set the active class in bootstrap navbar?

I am using bootstrap nav bar with codeigniter as backend.
Now In my application i want to change the < li> class to active dynamically for each page.
So i can known i am on which page currently.
Below is my code:
<ul class="nav navbar-nav">
<li class="active">Dashboard</li>
<li>Company</li>
<li>Users Management</li>
<li>Key Management</li>
<li>Activated Devices</li>
</ul>
<ul class="nav navbar-nav navbar-right">
You can use this javascript to add active class based on current url please try it
<script type="text/javascript">
$(document).ready(function () {
var url = window.location;
$('ul.nav a[href="'+ url +'"]').parent().addClass('active');
$('ul.nav a').filter(function() {
return this.href == url;
}).parent().addClass('active');
});
</script>
Can't you just use this replacing your <a> tags. This will match the current uri string, with the links href attribute. If it matches, it add's an active class to the link. You can style the .active using you
Company
So the entire code will be.
<ul class="nav navbar-nav">
<li>Dashboard</li>
<li>Company</li>
<li>Users Management</li>
<li>Key Management</li>
<li>Activated Devices</li>
</ul>
<ul class="nav navbar-nav navbar-right">
Your pages should know which menu should be set as active.
Try adding an id to your <li> and add a javascript code to your pages to set the active menu based on the ID.
Example:
<ul class="nav navbar-nav">
<li id="menu-dashboard" class="active">Dashboard</li>
<li id="menu-company">Company</li>
<li id="menu-user">Users Management</li>
<li id="menu-key-management">Key Management</li>
<li id="menu-activation">Activated Devices</li>
</ul>
<script>
var menuid = "menu-dashboard";
$(function() {
$('.nav li').removeClass('active');
$(menuid).addClass("active");
});
</script>
Pages:
Add the following javascript lines to your pages
Company page
menuid = "#menu-company";
User page
menuid = "#menu-user";
You can achieve it by using jQuery or JavaScript.
jQuery example:
$('.nav li').click(function(){
$('.nav li').removeClass('active');
$(this).addClass('active');
});
The jQuery in the accepted answer do not know the difference if the visitor is coming from http://example.com or http://example.com/index.php and would not activate the "home" menu-item. This is my fix for that.
HTML This is a snippet from my menu:
<div class='navbar'>
<a href='index.php'><div class='nav-icon icon-home'></div>Hem</a>
<a href='calender.php'><div class='nav-icon icon-calender'></div>Kalender</a>
<a href='exchange.php#utbyte'><div class='nav-icon icon-byte'></div>Byten</a>
</div>
This is a function I've added to my database controller class to find out what protocol the visitor use:
public static function adr_protocol()
{
$str = 'http://';
if(isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS']) $str = 'https://';
return $str;
}
jQuery:
;var ix = '<?php echo DBController::adr_protocol()."{$_SERVER['HTTP_HOST']}/"; ?>';
var url = (window.location==ix)?window.location+'index.php':window.location;
$('div.navbar a[href="'+ url +'"]').parent().addClass('active');
$('div.navbar a').filter(function() {
return this.href == url;
}).addClass('active');

Umbraco 6 razor menu

Hi I want to add a class of "active" to my li, if it is active or if I am on a page under that. I have the following code
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = null;
}
<nav class="topNav">
<ul>
#foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
<li>
#item.Name
</li>
}
</ul>
</nav>
I think I can do something with this, but it gives an error
var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
<li class="#Html.Raw(isSelected)">
#item.Name
</li>
This is the error I get. Line 10.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'Path' and no extension method 'Path' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 8: #foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
Line 9: {
Line 10: var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
Line 11:
Line 12: <li class="#Html.Raw(isSelected)">
I have now tried with this, but no lunk
<ul>
<li>
#home.Name
</li>
#foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
var isSelected = item.IsDescendant(Model,"active", "");
<li class="#Html.Raw(isSelected)">
#item.Name
</li>
}
</ul>
ok here is the solution. This is for typed, not dynamic cshtml.
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = null;
var home = Model.Content.AncestorOrSelf(1);
}
<ul>
#*Render Home item*#
#{ var homeActive = ""; }
#if( home.Id == Model.Content.Id){
homeActive = "active";
}
<li class="#homeActive">
<a href="#home.Url">
#home.Name
</a>
</li>
#*Render Home children*#
#foreach (var item in home.Children.Where(x => x.IsVisible()))
{
var active = "";
if(home.Id != Model.Content.Id){ #* if NOT home *#
if (item.Id == Model.Content.AncestorOrSelf(2).Id){
#* if foreach id and currentpage ancestor id is equal *#
active = "active";
}
}
<li class="#active">
<a href="#item.Url">
#item.Name
</a>
</li>
}
</ul>
You can try something like this:
var isSelected = item.IsDescendant(Model,"active", "");
Here is a list of the functions you can use:
#Model.AncestorOrSelf(string nodeTypeAlias)
#Model.AncestorOrSelf(int level)
#Model.AncestorOrSelf(Func<DynamicNode, bool> func)
and those Helper functions:
#Model.IsDescendant(DynamicNode[,valueIfTrue][,valueIfFalse])
#Model.IsDescendantOrSelf(DynamicNode[,valueIfTrue][,valueIfFalse])
Reference: Is the current page a descendant of a specific node id?
The following is the default script for navigation produced by umbraco:
#inherits umbraco.MacroEngines.DynamicNodeContext
#*
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 = Model.AncestorOrSelf(1);
}
<ul>
#foreach (var page in root.Children.Where("Visible"))
{
<li class="#page.IsAncestorOrSelf(Model, "current", "")">
#page.Name
</li>
}
</ul>
I just created a menu myself and needed the Home page to be active also. Working with just the method IsAncestorOrSelf doesn't work for the homepage.
The piece of code I've created is this:
#{
var root = Model.AncestorOrSelf(1);
var homeClass = root.Id == Model.Id ? "active" : "";
}
<ul id="nav" class="nav navbar-nav pull-right">
<li class="#homeClass"><a href="/" >Home</a></li>
#foreach (var page in root.Children.Where("Visible"))
{
<li class="#page.IsAncestorOrSelf(Model, "active", "")">
#page.Name
</li>
}
</ul>
This iterates through all children of the root node (1). To be able to discover if you are on the Home page, I'm checking the Id's of the page and set the active class accordingly.

Multi Level Drop down Menu using Razor in Umbraco

I am trying to build a multi-level dropdrown menu, I'm using umbraco cms.
What I am looking for is something like :
<div id="TopMenu">
<ul class="myMenu">
<li>Home</li>
<li>About Us</li>
<li>Products
<ul>
<li>Products1</li>
<li>Products2</li>
<li>Products3</li>
</ul>
</li>
<li>ContactUs</li>
</ul>
</div><!--TopMenu-->
And in Umbraco I have created cshtml for it to work :
<ul class="myMenu">
<li>Home </li>
#foreach (var page in #Model.AncestorOrSelf(1).Children)
{
string style = "";
if (1 == 1) { style = "class=\"current\""; }
<li><a href="#page.Url" #style>#page.Name</a></li>
}
The Above razor syntax works fine for AncestorOrSelf(1) which is Top level , but i need sub nodes for products which is AncestorOrSelf(2), Does any one knows how to acheive this
Thanx
This is the razor code I'm currently using in my project:
#foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible"))
{
<li>#page.Name
if (page.Children.Where("Visible").Count() > 0)
{
<ul>
#foreach (var subpage in page.Children.Where("Visible"))
{
<li>#subpage.Name</li>
}
</ul>
}
</li>
}
The inner loop cycles through all the children of the outer loop's node.