ASPX templates
Version 3.x > ASPX templates > My tips with CMSMenu View modes: 
User avatar
Member
Member
kurt.farrar-mydigitalmedia.co - 10/9/2008 5:47:18 PM
   
My tips with CMSMenu
Hi all,

I'm new to Kentico, having just signed up as a partner as I've a couple of clients interested in the products, and like for like I feel it's a superb tool, particularly for small businesses here in the UK (my target).

Anyway, I've been moving my own site over to Kentico, as I felt I couldn't really sell how good it is if I don't use it myself, and I ran into a few problems, which aren't really problems, but just weren't obvious to find the answers to. I tried searching DevNet and didn't find any related results, so I figured since I've worked out how to do what i want to do, I'll post my tips here for others to hopefully find if they're having the same problems.

How to add the CMSMenu control
=====================

I found that the tutorial suggests that it's in the toolbox after adding CMS.Controls.DLL, but this isn't the case.The Control examples show how you can use this component, and it's actually located in CMSAdminControls, I assume its in the compiled dlls somewhere, but at least this exposes the component for me to use.

So add:

<%@ Register Src="~/CMSAdminControls/PageTitle.ascx" TagName="PageTitle" TagPrefix="cms" %>

to the top of your (master) page.

Then within your layout add:

<cms:CMSListMenu ID="Vertical" runat="server" HighlightedNodePath="/Home" CSSPrefix="Main;SubMenu;OtherSubMenus"
FirstItemCssClass="first" LastItemCssClass="last"
DisplayHighlightedItemAsLink="True" WhereCondition="NodeLevel = 1" />


Limiting the menu using the WhereCondition
============================

Next problem that I came across is that my menu was showing all levels of my pages within my site. I could exclude individual pages from the navigation by changing their individual properties, but I later found that this would exclude them from the breadcrumb control.

I had a look around for how to use the WhereCondition. Like the CMSMenu, I couldn't find anything on DevNet as to how to make full use of the WhereCondition, or even how to simply limit it to just the first level of pages.

I had a guess at the syntax and put Level = 0 (I figured I'd try zero based first and if it doesn't error then I'll nudge it up to 1). Anyway, it errored straight away, but thankfully the error message displayed the SQL Query that was being executed, I was able to run this, without my Level = 0 included and managed to browse through the available fields to find out where the level is specified. Eureka! I found it, and for anyone who's wanting to limit the levels here's how...

In the WhereCondition property of your CMSMenu control enter:

NodeLevel = 1 (for 1st level, amend to show other levels).

I hope that my 5 minutes of tips will be of some use to someone somewhere, and to the guys at Kentico, keep up to the good work.

Kurt Farrar
Small Business IT Consultant

MyDigitalMedia
kurt.farrar@mydigitalmedia.co.uk
http://www.mydigitalmedia.co.uk

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/10/2008 8:00:54 AM
   
RE:My tips with CMSMenu
Hi Kurt,
Thank you for your useful post. It may help many users. I would like to add some more information about it.

Regarding to the first problem:
Here you can find information how to add the Kentico control to the Toolbox in Visual Studio - http://www.kentico.com/docs/devguide/adding_kentico_cms_controls_to.htm

Here is more information about creating ASPX page template - http://www.kentico.com/docs/devguide/creating_a_new_aspx_page_templ.htm. You can register the controls DLL as mentioned in that article or you can also drag and drop the control from the toolbox.

Regarding the WHERE condition:
It is standard SQL WHERE clause so in that field (or as a parameter value) you can use the standard SQL syntax as usual.

Moreover, when using web parts - in the menu web part and some others there is a field named "Maximum nesting level:" - here you can enter the number of levels you want to be listed (value -1 for all levels, by default). In ASPX controls is the parameter name "MaxRelativeLevel="<int_value>"". More information about common web part properties is available at http://www.kentico.com/docs/devguide/common_web_part_properties_and.htm.

Information about controls - http://devnet.kentico.com/docs/controls/index.html

Best Regards,
Juraj Ondrus

User avatar
Member
Member
kurt.farrar-mydigitalmedia.co - 10/10/2008 4:55:02 PM
   
RE:My tips with CMSMenu
Hi Juraj,

I originally followed the instructions on the page you specified, and I did have a look at all of the documentation first before anything else:
http://www.kentico.com/docs/devguide/adding_kentico_cms_controls_to.htm

Following these instructions does not add the CMSMenu control to the toolbox for me... perhaps I'm missing something. It add a whole bunch of other controls, but not the CMS Menu. To help, I'm running Visual Studio Team System 2008 on Windows Vista Ultimate, chose the option to install for .NET Framework v3.5 and Visual Studio 2008. Added the controls to the toolbox by selecting the DLL exactly as instructed. I'm running the latest v3.1a of Kentico.

Similarly, I sussed that it was raw T-SQL when I saw the SQL in the in error message, and that's when I went digging around the database.

Kindest Regards,

Kurt Farrar
Small Business IT Consultant

MyDigitalMedia
http://www.mydigitalmedia.co.uk

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/13/2008 2:19:46 AM
   
RE:My tips with CMSMenu
Hi again,

The description in Dev Guide is correct, but there is a bug with the menu controls in 3.1a version. So, you were right and I am sorry for this inconvenience. This problem is already fixed for the next release.


Best Regards,
Juraj Ondrus

User avatar
Member
Member
Erik - 5/5/2009 4:36:16 PM
   
RE:My tips with CMSMenu
We're using 4.0 and the CMSListMenu control to display a sidebar sub-menu with ASPX templates. I may be missing something here, but setting WhereCondition is not working for me. This is our markup:


<cms:CMSListMenu ID="subMenu" runat="server" ClassNames="CMS.MenuItem" DisplayOnlySelectedPath="true" />


and our code-behind:


subMenu.Path = Functions.GetPathLevel(Functions.GetAliasPath(), 1) + "/%";
subMenu.WhereCondition = "NodeLevel = 2";


This still displays the top level, and the selected path's sub-level. We want to display just the selected path's sub-level (a horizontal menu displays the top-level menu items already, so we do not need to have the entire structure in the sidebar).

Erik

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 5/18/2009 4:13:37 AM
   
RE:My tips with CMSMenu
Hi Erik,

You can use following macro in 'Path' property to ensure required behavior of menu: /{0}/%

Best Regards,

Martin Dobsicek