Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mico 10 posts 30 karma points
    Jan 30, 2014 @ 00:49
    mico
    0

    Creating a Navigation Menu with .NET usercontrol

    First hey everyone, im new with Umbraco.

    As a .NET developer im trying to avoid using the xslts at all and instead, use .NET UserControls as Macros.

    I want to create a UC which displays the different pages handled in the content area under the Umbraco system as my navigation menu. I know that I can easily achieve this by using xsltwith few clicks if i create a Navigation prototype, but i want to use .NET controls. Im trying to figure how this should be done considering the i fact my usercontrol should somehow know the different pages it should display. Where do i get this data from and also, are there any normal examples for .NET developers ? I can't really find advanced examples.

     

     

  • Graeme W 113 posts 289 karma points
    Jan 30, 2014 @ 10:26
    Graeme W
    0

    Hi Mico.

    No need to use xlst - you could try having a look at a couple of the starter kits. uBootstrap and the Standard website starter kits both use Razor\C# to build up menus based on your content nodes I've only got these running on Version 6 but the functionality should be the same on v7 I think

    http://our.umbraco.org/projects/starter-kits/ubootstrap

    http://our.umbraco.org/projects/starter-kits/standard-website-mvc

  • mico 10 posts 30 karma points
    Jan 30, 2014 @ 10:42
    mico
    0

    Thank you Graeme W I have just downloaded the files you pointed at. My only concern now is why the zip files doesn't contain the folder hierarchy? all the files are completly flattern into one folder, i'd like to test this but not sure if i should manually copy them to the correct places (I don't see any documentation..)

  • Graeme W 113 posts 289 karma points
    Jan 30, 2014 @ 11:24
    Graeme W
    0

    Hi Nico. Normally you can install packages by uploading the zip files directly into Umbraco from the Umbraco back office: Developer section - Packages - Install Local Package

    If you have any problems each of the starter kits have their own troubleshooting forums which might help

  • Jeppe Andreasen 10 posts 30 karma points
    Jan 30, 2014 @ 22:53
    Jeppe Andreasen
    0

    First of all just making sure you want to be writing a macro for this. A macro is a control you can insert inside the richtext editor. If this indeed is what you need, then go on writing the macro, otherwise just drop your user control on your masterpage.

    Anyway. What you need first, is to get the node of the page you are currently visiting. For that use :

    var currentNode = umbraco.NodeFactory.Node.GetCurrent()

    From there you can traverse back to the level before the first level of your menu : 

    const int minLevel = 2;

    var tmp = currentNode;

    while (tmp.Level >= minLevel) { tmp = tmp.Parent; }

    now you can render each node below the tmp item ( this will be the first level of the menu )

    foreach (var topLevelItem in tmp.Children)

          writer.Write("<a href=\" + topLevelItem.NiceUrl + "\">" + topLevelItem.Name + "</a>");

    Hope it helps

  • mico 10 posts 30 karma points
    Jan 30, 2014 @ 23:12
    mico
    0

    Graeme W

    I wasn't sure if i can install both packages on same project so I created 2 different projects (both based on WebForms)

    Ive installed the bootstrap package and I'm currently struggling with running the frontal website. The umbraco cms works fine but once i try to access any of the en.umbraco pages i can't really do that, im guessing that's something with the IIS but i didn't solve this issue yet.

    As for the second package, i wasn't really sure if the project should be webforms or mvc, as far as ive understand umbraco should be webforms, anyway ive installed this mvc website package but im getting many errors afterwards. sad to see there's no real documentation about this. feels like gambling.

    Jeppe Andreasen 

    Im guessing i should have state it better, ye it sounds like i pointed at a UC for my Masterpage. Your example seems logic to me i'd be testing this soon. Could you also tell me if there are any examples somewhere ? It feels like im about to invent everything from scratch and i cant really see decent examples around.

     

  • Per Ploug 865 posts 3491 karma points MVP admin
    Jan 31, 2014 @ 10:26
    Per Ploug
    0

    Keep it simple, use razor in your macros, Umbraco comes with plenty of templates for doing this in razor, just like you can it in xslt - no need to extra packages for addding something like navigation

  • Tom 161 posts 322 karma points
    Mar 13, 2015 @ 11:57
    Tom
    0

    Can someone direct me as to where the navigation templates in Umbraco line?

     

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft