Programmatically getting Dictionary value - formerly GetDictionaryValue()
Hi,
Under Umbraco 7 I used to have a method that would get a dictionary label and return the correct value. It used to be done with UmbracoHelper. How can this be done in Umbraco 8 now?
This is the old method:
public static string GetLabel(string label)
{
return umbracoHelper.GetDictionaryValue(label);
}
I have seen a number of other posts recommending using Umbraco. but this doesn't seem to work as I see no methods. Thank you for any help!
Genc
In my views in V8 I'm doing Umbraco.GetDictionaryValue("DictionaryItemAlias","FallBackValue")
In a view Umbraco is an exposed version of an UmbracoHelper much in the same way you are using it in your static method so it should still be possible.
Some thing to be aware of, ideally you shouldn't be creating your own instance of the Umbraco helper, you could consider creating an Extension method though.
This would rely on you having an instance of an UmbracoHelper which, hopefully, you aren't creating an instance of but using an already existing instance either from your view, your controller, or injected via dependency injection into custom code.
Thank you so much Nik. Made progress. I have one of those precompiled versions so had to change stuff all over the place. Looks like it is on the right track though. Thank you!
Programmatically getting Dictionary value - formerly GetDictionaryValue()
Hi,
Under Umbraco 7 I used to have a method that would get a dictionary label and return the correct value. It used to be done with UmbracoHelper. How can this be done in Umbraco 8 now?
This is the old method:
I have seen a number of other posts recommending using Umbraco. but this doesn't seem to work as I see no methods. Thank you for any help! Genc
Hey Genc,
In my views in V8 I'm doing
Umbraco.GetDictionaryValue("DictionaryItemAlias","FallBackValue")
In a view
Umbraco
is an exposed version of anUmbracoHelper
much in the same way you are using it in your static method so it should still be possible.Some thing to be aware of, ideally you shouldn't be creating your own instance of the Umbraco helper, you could consider creating an Extension method though.
E.g.
This would rely on you having an instance of an UmbracoHelper which, hopefully, you aren't creating an instance of but using an already existing instance either from your view, your controller, or injected via dependency injection into custom code.
Nik
Thank you so much Nik. Made progress. I have one of those precompiled versions so had to change stuff all over the place. Looks like it is on the right track though. Thank you!
If inheriting from UmbracoApiController / SurfaceController
Following may work :
BJ
is working on a reply...