Copied to clipboard

Flag this post as spam?

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


  • Solomon Closson 22 posts 42 karma points
    Oct 30, 2014 @ 04:09
    Solomon Closson
    0

    How to get UmbracoHelper working here?

    In a .cs file, I have the following:

    using Umbraco.Web.UI.Controls;
    
    namespace TESTING.Umbraco
    {
        public class UmbracoHelper
        {
            void Parse(UmbracoHelper node);
        }
    }
    

    Than, in another .cs file, I have the following:

    var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.UmbracoContext.Current);
    

    But Visual Studio is giving me flag on .Web, saying that the namespace Web does not exist in the namespace TESTING.Umbraco

    Basically, I would like to call a method inside my class files, called Parse() that would take UmbracoHelper into it, which will work, but I don't seem to have many properties for Umbraco Helper... example:

    private static Menu Parse (UmbracoHelper aNode)
    {
        aNode.??? (Not much to get here...)
    }
    

    How can I do this exactly? Seems I am not doing this right. I just want to get all properties from a node so that it can be outputted... UmbracoHelper is what I thought I needed, but doesn't seem like it is right, or I'm not using it right...

    Can anyone help me please?

  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 30, 2014 @ 14:53
    Dan Lister
    0

    Hi Soloman,

    From your last code example, you have named your parameter 'aNode'. An instance of the UmbracoHelper class is not a representation of a published page. It is a class to help with published content. For example, if you wanted to get a node, you would have to use the following method:

    var aNode = new UmbracoHelper(UmbracoContext.Current).TypedContent(123);
    

    Also, you have named your class UmbracoHelper. Are you trying to create an extension method or a class? If its the later, I would recommend naming it something else to not confuse things with Umbraco's UmbracoHelper class. Maybe something like the following:

    public static class UmbracoHelperExtensions
    {
        public static Menu Parse(this UmbracoHelper helper)
        {
            var rootId = 1234;
            var rootNode = helper.TypedContent(rootId);
            ...
        }
    }
    

    You would then be able to use the extension method as follows:

    var helper = new UmbracoHelper(UmbracoContext.Current);
    var menu = helper.Parse();
    

    Thanks, Dan.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 31, 2014 @ 07:00
    Sebastiaan Janssen
    0

    Just to add to this, it seems you are using the namespace Umbraco elsewhere as well. Make sure to avoid using Umbraco in your namespaces and classnames so that you don't clash with our namespaces and clssass names.

  • Solomon Closson 22 posts 42 karma points
    Oct 31, 2014 @ 19:44
    Solomon Closson
    0

    Hello, thanks for your feedback. I am not able to access UmbracoContext, only HttpContext is accessible. Why can I not access UmbracoContext? This is also the case for ApplicationContext. Both of these are inaccessible and cause errors. Only able to access HttpContext. Any suggestions on how to debug/fix this?

Please Sign in or register to post replies

Write your reply to:

Draft