Copied to clipboard

Flag this post as spam?

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


  • Siavash Mortazavi 24 posts 145 karma points
    Oct 14, 2016 @ 14:15
    Siavash Mortazavi
    0

    Reading From a Settings Node

    Hi,

    I'm using Umbraco 7.5.2. I have created a doc type for my "Global Settings" and have created a Content node on top of that document type.

    I have a static C# class, called SiteGlobalSettings that I use in my backend codes to handle global concerns.

    I want to have SiteGlobalSettings be able to read data from my "Global Settings" content node. In SiteGlobalSettings static constructor, I have this code:

    UmbracoHelper Umbraco = new UmbracoHelper();

    dynamic globalSettingsContent = Umbraco.Content(...global setting node id...);

    After running this code, globalSettingsContent will be null. I can see that UmbracoHelper has some constructor overloads. One of them recieves a UmbracoContext object, but it seems I cannot new it.

    Can someone help me achieve this please? Thank you.

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Oct 14, 2016 @ 16:38
    Alex Skrypnyk
    100

    Hi Siavash,

    Try to do it like that:

    UmbracoHelper Umbraco = new UmbracoHelper(UmbracoContext.Current);
    

    It's ok, can you share code of your view?

    Also it's not perfect to use dynamics, do you know?

    Thanks,

    Alex

  • Siavash Mortazavi 24 posts 145 karma points
    Oct 17, 2016 @ 15:59
    Siavash Mortazavi
    1

    Hi Alex,

    That works, thank you very much! :-)

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Oct 17, 2016 @ 16:09
    Alex Skrypnyk
    0

    Glad to help.

    Mark topic as solved and have a nice evening!

    Thanks,

    Alex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies