+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom page properties and menu

Custom page properties and menu

12 posts, 0 answered
  1. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi all,

    I've been researching into how i might split my navigation into two seperate menu's, one a utility menu / about / resources / downloads/ at the very top of the page, and one for the main navigation i.e. /products / services / contact etc.

    I have had some suggestions to group the utility menu pages under a sitemap node, but the seperation of these two menus isn't based on the url structure, its more a design/usability feature. If I can help it I dont want to have to place all of the utility menu items under a url such as /utilities/ because it will negatively affect how the search engines look at my structure and content.

    The only way i can see to feasibly acheive what I want is to create page properties such as :

    "Show in utility menu"
    "Show in main menu"

    And then create a custom control which queries the sitefinity database for all pages that have a property matching those listed above.

    The other alternative is to follow the tip in this blog article, http://www.sitefinity.com/blogs/ivandimitrov/ivanposts/10-02-13/sitemenu_builder.aspx, however this too isnt perfect because you have to select which pages you want to show in each menu, which I presume means content editors would have to update the menu control in every template when they added a new page.

    Any ideas page?

    Thanks in advance
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Al,

    The better option is using SiteMenuBuilder, but if you want to create custom page properties you can take a look at Custom page properties . You have to write your persistence classes to save these custom properties in your database.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    Do you mean the sitemenubuilder blog that i posted? If so, and being a relative newbie to sitefinity I couldn't get it to work. I copied the code exactly, and am able to drag the control onto a page via the sitefinity manager, I am then able to open the treeview and select multiple pages - however when i preview the page the menu is never shown, simply the label "Select a page from the tree".

    Am i doing something wrong? Am i not supposed to be dragging this control onto my template?

    Thanks again
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Al,

    There is no problem with the SiteMenuBuilder code from the blog post. I attached sample video that shows how the control works.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    Thanks for your response. I can see it working, perhaps I've done something wrong to start with.

    I have ended up with three files:

    - DynamicMenuBuilder.cs
    - DynamicMenuBuilderWebUITypeEditor.cs
    - PageIDWebEditor.ascx and .ascx.cs

    I think where I have gone wrong is that I have uploaded the user control and dragged that onto my template, wheeras from looking at the video you sent over, it looks like you have uploaded the .CS file. How did you get these into SiteFinity - did you compile them into .dll files?

    Thanks again
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Al,

    In App_Code( or compiled to a dll)

    - DynamicMenuBuilder.cs
    - DynamicMenuBuilderWebUITypeEditor.cs

    This is user control
    - PageIDWebEditor.ascx and .ascx.cs

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    Am i right in saying then that it is the DynamicMenuBuilder.cs file that is the Sitefinity control that must be dragged and dropped onto my templates? If so, how did you do this.? Did you just compile the .cs file into a .dll file, or is there another way of doing it?

    Regards,
    higgsy
  8. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    I compiled the DynamicMenuBuilder.cs file using the following command line:

    C:\Windows\Microsoft.NET\Framework\v3.5>csc /nologo /target:library /out:D:\phoenix\www\bin\control.dll /r:D:\phoenix\www\bin\Telerik.cms.dll,D:\phoenix\www\bin\Telerik.Cms.Web.UI.dll,D:\phoenix\www\bin\Telerik.web.ui.dll,D:\phoenix\www\bin\Telerik.Framework.dll,D:\phoenix\www\bin\Telerik.security.dll D:\phoenix\www\App_Code\DynamicMenuBuilder.cs

    This gave me the control.dll file, which I was able to upload to my SiteFinity instance.

    I can now drag the dynamicmenubuilder control into a page, click to edit, and select multiple pages. However, after selecting multiple pages and clicking "Im done", the code crashes, and the following error is shown:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Line 27: 				if (node != null) {
    Line 28: 					CmsSiteMapNode smNode = (CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/" + node.FullPath + ".aspx");
    Line 29: 					ICmsPage cmsPage = manager.GetPage(smNode.CmsPage.ID) as ICmsPage;
    Line 30: 					pageId = cmsPage.ID;
    Line 31: 					selectedIds.Add(pageId);

    Source File: d:\phoenix\www\App_Code\DynamicMenuBuilderWebUITypeEditor.cs

    Any ideas why this might be happening?

    Thanks again in advance
    higgsy

  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hello Al,

    smNode is null because it si not found by SiteMap.Provider.FindSiteMapNode.
    This could happen if you use extensionless urls and there is no .aspx
    extnesion and you have to remove it from the code or create a new property that
    specifies whether extnesionless urls are enabled
    You can also verify FullPath of the node to see what it returns and whether 
    this node exists in your SiteMap
    

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    I've just debugged it and can see exactly where it happens. Most of my pages have the same page name as they do a menu label, therefore

    Products - has a page called Products.aspx

    However, my news page is like so:

    News & Events - has a page called simply news.aspx

    When i placed a breakpoint on the following line:

    CmsSiteMapNode smNode = (CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode("~/" + node.FullPath + ".aspx");

    I could see that the node.FullPath that was being returned for the news & events page was actually "News & Events", which obviously does not exist.

    I think the node.fullPath needs to be something more like node.url.

    Presumably I will have to get the node's text (which will be the selected page's ID), use that to get hold of the page, and then extract the url? Or something like that?

    Thanks again
    higgsy
  11. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hi Ivan,

    Any thoughts on how to fix this problem? In my example, it looks like node.FullPath is returning "News & Events".aspx, which is actually the page title, whereas the actual filename/url is "news".aspx.

    Thanks
    higgsy

  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Al,

    Inside PageIDWebEditor add attributes to the node and set NavigateUrl. Then when you call SiteMap.Provider.FindSiteMapNode read the attribute

    PageIDWebEditor.ascx.cs

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        foreach (RadTreeNode n in RadTreeView1.GetAllNodes())
        {
            n.Attributes.Add("urlKey", n.NavigateUrl);
            n.NavigateUrl = "";
        }
        
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
12 posts, 0 answered