Pulling values from appsettings.json in Block List and Grid
Hi,
I have got an issue in Umbraco 13 I can't for the life of me work out how to pull some custom settings I have setup in the appsettings.json file for goodle maps in to a Block Grid or Block List.
In the version 8 site we use.
var apiKey = System.Configuration.ConfigurationManager.AppSettings["googleAPIKey"];
But this dose not work in version 13.
Can any one help. I dont want to have to write my own JSON parser if I dont have to,
@{
var maplat = Model.Content.Value("latitude").ToString();
var maplng = Model.Content.Value("longitude").ToString();
var apikey = _configuration["CustomSettings:googleAPIKey"];
Pulling values from appsettings.json in Block List and Grid
Hi,
I have got an issue in Umbraco 13 I can't for the life of me work out how to pull some custom settings I have setup in the appsettings.json file for goodle maps in to a Block Grid or Block List.
In the version 8 site we use.
var apiKey = System.Configuration.ConfigurationManager.AppSettings["googleAPIKey"];
But this dose not work in version 13.
Can any one help. I dont want to have to write my own JSON parser if I dont have to,
Example is for a view / partial but same idea for controller / view component.
Inject the configuration - so for a view:
@inject IConfiguration _configuration
(possibly need @inject Microsoft.Extensions.Configuration.IConfiguration _configuration)
Then you can access values in the Json like this:
Or if it's not a string - you can use get value to use type setting:
Thanks you
get the following code to work:
@using Umbraco.Extensions @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@{ var maplat = Model.Content.Value("latitude").ToString(); var maplng = Model.Content.Value("longitude").ToString(); var apikey = _configuration["CustomSettings:googleAPIKey"];
}
is working on a reply...