Continued Graffiti goodness. Here is another Graffiti customization - the GetAppSetting Chalk extension. I recently put this one together so I haven’t grown to love it as much as the RedirectIfSinglePost extension, but it is very handy to have around when you need it.
What does it do?
You use it to pull a AppSettings configuration value from your web.config file. I think Graffiti’s Custom Fields are great and I use them all the time, but I’ve found that sometimes I just need access to a custom value that is the same for all posts or categories. Storing that value in the web.config makes a lot of sense and we ASP.NET developers are used to utilizing the AppSettings section. But I couldn’t find an easy way to access the web.config AppSettings inside my views. So I wrote a new Chalk extensions to do just that. This really isn’t all that powerful by itself, I could have just hard-coded a string in the view, but it’s really useful for storing something like an Amazon or Twitter API key that’s used in calls for other Chalk extensions.
1: namespace DanHounshell.Graffiti.Chalk
4: public class ConfigurationAppSettings
6: public string GetAppSetting(string setting)
8: return ConfigurationManager.AppSettings[setting];
Just place the following wherever you need it in your view markup:
As I mentioned, I find this most powerful when mixing with other Chalk extension calls. Here’s an example of a fictional call to a Chalk extension that hits the Ebay Web Service to return 10 products that match the search term “dell laptop”. The GetAuctions method expects my Ebay API key. Rather than hard-coding it into my view I instead store in the AppSettings section of my web.config file and use the GetAppSetting call to pull it out:
1: $EbayService.GetAuctions("dell laptop",
I hope you find this Graffiti Chalk extension useful. Please leave a comment if you have any suggestions or questions.