3

In C#, I'm trying to read the value of a configuration parameter. I do this from outside a AlchemyApiController and the problem is the Plugin property. It is not available:

int days = Plugin.Settings.Get<int>("NumberofDays");

The code above works fine from within a controller. How can I read this value from anything else than a controller?

Thanks in advance!

3

To my knowledge, plugin settings are only available on Controllers and JS Resource files.

Alchemy Controllers are inherited from the class AlchemyApiController and since Plugin property is defined in AlchemyApiController that's why Plugin.Settings only available on the controllers. Other than controllers the plugin settings could be accessed on the JS resource files like Alchemy.Plugins["${PluginName}"].Api.getSettings() but under the hood, this calls the same web API used by Plugin.Settings. Plugin settings are configuration values for controlling the behavior of a plugin and usually set by the Plugin Users.

When you say "anything else than a controller", I guess you mean configuration classes like CommandSet, ContextMenuExtension, ResourceGroup etc. Since these files define the configuration of the plugin in Tridion (and not it's functionality) set by the plugin author and execute only once at the installation time of the plugin so It makes sense not to have access to the settings in these classes. The settings could be updated for an installed plugin later and They won't be useful in those configuration classes even if you get access to the settings in the classes.

It would be interesting to know why do you want to access setting in other classes.

  • 1
    In my case, I have a plain data object that I use to serialize into JSON as the response of my Alchemy Controller. During this serialization I want to use a settings value (e.g. number of days a resource is active). I can't do this with the current Alchemy Plugin.Settings architecture. Instead, I need to create some kind of Configuration Manager that I call from the Controller to populate a custom 'settings' data object, which then I make available to my JSON serializer... Doable, but much less than ideal. – Mihai Cădariu Nov 4 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.