Understanding the DNN API
Last Post 02/24/2016 12:08 PM by Stephen. 8 Replies.
Author Messages Not Resolved
Stephen
Nuke Pro
Nuke Pro
Posts:86


--
05/12/2015 2:15 PM  
Hello,

I would like to determine the code required to display the items of a DNN menu. At this stage, I think I just need the page/tab name and link in the hierarchy.

I assume the way to do this is to loop recursively through the tab collection taking into account things like page visibility for a given user, deleted pages etc.

What is the best way to determine this code rather than attempting to write it from scratch?

Is there a resource with code samples? I haven't been able to find such a thing. Is it really a case of searching through the DNN source code which seems quite daunting.

Best Regards,

Steve
Joseph Craig
DNN MVP
Posts:11667


--
05/12/2015 3:04 PM  
Probably the best way to do this is to use the DDR menu. You can use it as a skin object or as a module.

IT IS TEMPLATABLE!

The basic DDR menu outputs an XML package that contains everything that you need to know about the page structure. Your template (can be based on tokens, and XSLT transform, or a Razor script) transforms the page structure into an HTML structure that can be dropped into your page.

Search for "DDR" in the DNN Wiki at dnnsoftware.com. Example templates can be downloaded from codeplex.com. The examples range from a simple nested ul construct to a "mega" menu complete with javascript. You will find other examples if you Google around.

Also, look at out bootstrap skinning tutorials, several of which show how to create a custom template. Searching for DDR from out home page will provide you with a double-handful of tutorials.

Joe Craig, Patapsco Research Group
Complete DNN Support
Stephen
Nuke Pro
Nuke Pro
Posts:86


--
05/13/2015 8:20 AM  
Hi Joe,

Thank you for your reply.

DDR menu sounds a really good idea, I didn't realise it's templatable.

Will check the videos too.

Thank you once again.

Best Regards,

Steve

Stephen
Nuke Pro
Nuke Pro
Posts:86


--
02/15/2016 9:26 AM  
Hi Joe,

I'm just relooking at the DDR menu that we spoke about some time ago. I did have a look at the time, but still can't figure it out.

I found some sample Razor code that I think you were refering to:
http://www.dnnsoftware.com/wiki/ddr...-templates


Aside, I'm using the following C# to run all Razor code snippets in my module:

//***********************************************************
string FullFileName = @"/desktopmodules/modulename/Templates/somefilename.cshtml"; //Razor File

ModuleContext mc = new ModuleContext();
string lLocalResourceFile = "";
var writer = new StringWriter();

var razorEngine = new DotNetNuke.Web.Razor.RazorEngine(FullFileName, mc, lLocalResourceFile);

//Render the result
razorEngine.Render(writer, MyObject);
//************************************************************

Where 'MyObject' is the object to be accessed as the 'Model' in the Razor file.
In the Razor file, I use the following line to reference the 'Model':
@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage

This all works fine, but for the DDR menu code I can't work out which object to pass in as the Model.

I was thinking it could be 'DotNetNuke.Entities.Tabs.TabInfo', but that doesn't have the Source.root member.

Any ideas where I could try and find this?

All the best,

Steve
Stephen
Nuke Pro
Nuke Pro
Posts:86


--
02/15/2016 9:34 AM  
The line '@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage' in the previous reply should be postfixed with the object type in angle brackets. But that isn't showing for some reason.
Joseph Craig
DNN MVP
Posts:11667


--
02/17/2016 8:17 PM  
Steve,

I really can't speak to this, but ... I'm guessing that what you want is the object that is passed to the template. You can look at the source for the DDR module to try to figure that out.

Joe Craig, Patapsco Research Group
Complete DNN Support
Stephen
Nuke Pro
Nuke Pro
Posts:86


--
02/22/2016 7:03 AM  
Hi Joe,

Thank you for your reply.

OK so i need to look at the code. Didn't realise that DDR is a module, thought it was a skin object.

Assume you mean download from here?:
https://github.com/dnnsoftware/Dnn.Platform/tree/development/DNN%20Platform/Modules/DDRMenu
Will download and have a look.

Thank you once again.

Best Regrds,

Steve
Joseph Craig
DNN MVP
Posts:11667


--
02/22/2016 10:56 AM  
It is actually a skin object AND a module. You can use it either way.

Joe Craig, Patapsco Research Group
Complete DNN Support
Stephen
Nuke Pro
Nuke Pro
Posts:86


--
02/24/2016 12:08 PM  
Hi Joe,

I didn't find it as a module, but managed 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 addtional references required: DotNetNuke.Web.DDRMenu
Maybe some other references, i just can't remember exactly, but visual studio will point that out.


---