Copied to clipboard

Flag this post as spam?

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


  • Damien 36 posts 160 karma points
    Mar 13, 2019 @ 09:59
    Damien
    0

    UmbracoHelper & Dictionary V8

    Hi,

    Anyone have a example of using UmbracoHelper in V8:

    https://our.umbraco.com/documentation/Reference/Querying/UmbracoHelper/

    Above docs are not updated for V8 yet.

    I'm trying to use within a form partial to grab a dictionary item.

    Thanks Damien

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Mar 13, 2019 @ 10:06
    Sebastiaan Janssen
    0

    It depends a bit on where you're using it but if you're in any class that inherits from an Umbraco base class (a SurfaceController for example), Umbraco is the UmbracoHelper, so you can go:

    var dictionary = Umbraco.GetDictionaryValue("testing");

  • Damien 36 posts 160 karma points
    Mar 13, 2019 @ 10:28
    Damien
    0

    Thanks, I'm within the default Umbraco Forms partial view, Umbraco.GetDictionaryValue is not available.

    Trying to get around this issue: https://issues.umbraco.org/issue/CON-1161

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Mar 13, 2019 @ 10:47
    Sebastiaan Janssen
    102

    Aha, gotcha, this should work:

    • Forms.cshtml starts with @inherits WebViewPage<Umbraco.Forms.Web.Models.FormViewModel>
    • Change that to @inherits UmbracoViewPage<Umbraco.Forms.Web.Models.FormViewModel> to get all the lovely Umbraco magic in there
    • Then you can use Umbraco.GetDictionaryValue
  • Marc-André 44 posts 226 karma points
    May 06, 2019 @ 18:58
    Marc-André
    0

    Pure genuis! Give this guy a trophy :D

  • Damien 36 posts 160 karma points
    Mar 13, 2019 @ 10:51
    Damien
    0

    Perfect, thank you.

  • Thomsen 76 posts 268 karma points
    Mar 13, 2019 @ 22:08
    Thomsen
    0

    And if one should use the UmbracoHelper in a custom class or service etc., this syntax normally works in v7:

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

    But it fails in v8 - is there a new way of doing this now?

  • Sebastiaan Janssen 4843 posts 14347 karma points MVP admin hq
    Mar 14, 2019 @ 06:56
    Sebastiaan Janssen
    0

    @Thomsen - you would use dependency injection (I wrote a bit more about that here) to get the thing you want from the UmbracoHelper, however if you're in any class that inherits from an Umbraco base class (a SurfaceController for example), Umbraco IS the UmbracoHelper so you'll want to try typing Umbraco. and look at the autocomplete.

    If that doesn't give you what you're looking for then leave a comment with what exactly you would want to get from the UmbracoHelper and I'll help you along. Most people would probably be looking for the content cache, I wrote a bit more about that here: https://our.umbraco.com/forum/umbraco-8/96165-v8-umbracohelpercontent-and-umbracohelpertypedcontent-where-has-it-gone#comment-304114

  • Damien Holley 64 posts 231 karma points
    May 12, 2019 @ 09:37
    Damien Holley
    0

    Hi Sebastian, I need to be able to query the ContentAtRoot from within my general functions, as the user needs to be able to add an admin email into the backoffice, and my general email function needs to be able to 'see' it. (Also need to get to the richtext box as the user can enter a footer for all emails)

    The code you linked to has little in the way of explanation ie: When the namespace is Umbraco8 is that == YourProjectName or does it have to be the former?

    Do you know what would be best practice to do what I need to do?

    I have noticed several other explanations, however I also need to know how to call these functions from within code that does not have access to the UmbracoHelper models. All your examples seem to be geared towards running them from a viewpage or some other area exposed to these models. I'm guessing I am missing something pretty big, so thanks for any examples you can give.

  • christian Boutet 10 posts 100 karma points
    May 10, 2019 @ 15:06
    christian Boutet
    0

    We had some issue in version 7.x where the GetDictionaryValue was hitting the database each time we use it. At that time we decide to use Vettvangur.DictionaryHelper who cache the dictionary on startup.

    Anyone know if this issue is fix in Umbraco 8?

    Thanks,

  • Marc Love 305 posts 770 karma points
    15 days ago
    Marc Love
    0

    Hi,

    Anyone know how to get access to UmbracoHelper > Dictionary items within a PropertyValueConverter?

    Cheers,

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft