I’m in the process of creating my first Alchemy Extension that uses custom configuration settings and I thought I’d share some learning as I go as I think it’s safe to say a good chunk of all extensions will use some sort of custom configuration.
So the first place to start is the API docs, there’s a great post here about getting started here.
So in my plugin’s A4T.xml file I had (at first) the following XML:
<settings> <Category>874</Category> <PubId>42</PubId> </settings>
All good so far (hint, for what I’m doing this isn’t quite right, but we’ll get to that).
So i’m using JavaScript to access these settings in my extension interface, i’m using the following code:
Alchemy.Plugins["${PluginName}"].Api.getSettings() .success(function (settings) { Â Â $messages.registerGoal("Settings are: " + JSON.stringify(settings)); }) .error(function () { Â Â $messages.registerError("There was an error", error.message); }) .complete(function () { Â Â progress.finish(); });
Which is actually all good code, but when I came to test the result, I saw that no data is coming back.
Thankfully I can ask Alex Klock what i’m doing wrong (and most likely you can too, he’s insanely helpful), and he informed me that I need to wrap the XML nodes that I’d like either like this:
<settings> <Category client="true">874</Category> <PubId client="true">42</PubId> </settings>
Or like this:
<settings> <client> <Category>874</Category> <PubId>42</PubId> </client> </settings>
So you may see now where I went wrong? Â – that’s right, I’d not told the XML that certain configuration nodes are available to the client by adding either the <client> node, or the client=”true” attribute.
This is actually documented in the Alchemy API docs, but if I missed them, perhaps you will too.
And if you’ve not read those docs, but you read this blog, you may not even realise that it’s possible to add these configuration settings to your Alchemy extensions.
I missed this the first time too John, good point.