Forum


HomeHomePremiumPremiumDevelopmentDevelopmentRunning Razor Menu code within a moduleRunning Razor Menu code within a module
Previous
 
Next
New Post
10/15/2015 9:13 AM
 
Hello,

I'm trying to build a DNN menu into a module I'm developing. Firstly, I'd just like to get the menu code to render using Razor, I can apply CSS later. I've looked at a lot of articles but tried the code from here: http://www.dnnsoftware.com/wiki/ddrmenu-razor-templates (please see relevant code below).

I tried inserting my own Razor templates using RenderPage i.e. @RenderPage(string filepath, params object[] data)
I pass in the Model via the data parameter and retrieve in in the template via PageData, this works fine with my own razor templates, but how can i make this work for the menu code? I assume I need to pass in the Model, but what to pass in? Could someone please give me a hint.

All the best, 

Steve


@using DotNetNuke.Web.DDRMenu;
@using System.Dynamic; 
@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage

@{ var root = Model.Source.root; }



@helper RenderNodes(IList nodes) {

if (nodes.Count > 0) {



@foreach (var node in nodes) {

var cssClasses = new List();

if (node.First) { cssClasses.Add("first"); }

if (node.Last) { cssClasses.Add("last"); }

if (node.Selected) { cssClasses.Add("selected"); }

var classString = new HtmlString((cssClasses.Count == 0) ? "" :

 (" class=\"" + String.Join(" ", cssClasses.ToArray()) + "\""));


@if (node.Enabled) {

@node.Text

} else {

@node.Text

}

@RenderNodes(node.Children)

}

}
}

@RenderNodes(root.Children) 
 
New Post
2/29/2016 9:37 AM
 
Finally, i got around to searching though the source code for DNN 7 to find the required code in the DNN source. 


For anyone who might be interested, I created class to retrieve the menu details, please see below. 
I excluded most of the settings but it gives me what i need.
 

Steve 

//******************************************************
public class MyMenu: DotNetNuke.Web.DDRMenu.ModuleBase 

public static int GetNavNodeOptions(bool includeHidden) 

return (int)DotNetNuke.UI.Navigation.NavNodeOptions.IncludeSiblings + (int)DotNetNuke.UI.Navigation.NavNodeOptions.IncludeSelf + 
(includeHidden ? (int)DotNetNuke.UI.Navigation.NavNodeOptions.IncludeHiddenNodes : 0); 


public DotNetNuke.Web.DDRMenu.MenuNode GetMenu(EventArgs e) 

DotNetNuke.Web.DDRMenu.MenuNode rootNode = null; 
using (new DotNetNuke.Web.DDRMenu.DNNCommon.DNNContext(this)) 

try 

base.OnPreRender(e); 

//var menuStyle = GetStringSetting("MenuStyle"); 
//if (String.IsNullOrEmpty(menuStyle)) 
//{ 
// rootNode = null; 
// return rootNode; 
//} 

var menuSettings = new DotNetNuke.Web.DDRMenu.Settings 

MenuStyle = "", //GetStringSetting("MenuStyle"), 
NodeXmlPath = "", //GetStringSetting("NodeXmlPath"), 
NodeSelector = "", //GetStringSetting("NodeSelector"), 
IncludeContext = false, //GetBoolSetting("IncludeContext"), 
IncludeHidden = false, //GetBoolSetting("IncludeHidden"), 
IncludeNodes = "", //GetStringSetting("IncludeNodes"), 
ExcludeNodes = "", //GetStringSetting("ExcludeNodes"), 
NodeManipulator = "", //GetStringSetting("NodeManipulator"), 
//TemplateArguments = 
// DotNetNuke.Web.DDRMenu.Settings.TemplateArgumentsFromSettingString(GetStringSetting("TemplateArguments")), 
//ClientOptions = 
// DotNetNuke.Web.DDRMenu.Settings.ClientOptionsFromSettingString(GetStringSetting("ClientOptions")) 
}; 

rootNode = 
new DotNetNuke.Web.DDRMenu.MenuNode( 
DotNetNuke.Web.DDRMenu.Localisation.Localiser.LocaliseDNNNodeCollection( 
DotNetNuke.UI.Navigation.GetNavigationNodes( 
ClientID, 
DotNetNuke.UI.Navigation.ToolTipSource.None, 
-1, 
-1, 
GetNavNodeOptions(menuSettings.IncludeHidden)))); 

catch (Exception Ex) 



return rootNode; 





There were some additional references required for example: DotNetNuke.Web.DDRMenu 
Maybe some other references are also required, i can't remember now exactly which one i added, but visual studio will point that out.

 
New Post
2/29/2016 9:48 AM
 

This is what I call perseverance Steve! Thanks for coming back and addressing your own question!

Cheers,

Aderson

 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentRunning Razor Menu code within a moduleRunning Razor Menu code within a module



Try FREE
30 days money back guaranteed