Graffiti CMS Extension for DotNetKicks

Date Published: 18 September 2008

Graffiti CMS Extension for DotNetKicks

I’ve been manually adding DotNetKicks icons to my posts recently to try and generate more buzz for them, but that gets old quickly, so about an hour ago I decided to figure out how to make this automatic. My current blog engine is Graffiti, which I really like, and after doing some searching for a pre-existing solution, I pinged ScottW on IM about the problem and he set me down the right path within seconds.

The Problem

DotNetKicks will display a dynamic image with a count of how many “kicks” a particular post has had. It looks something like this:

kick it on

The HTML for this icon is very simple, and the only dynamic part of it is the URL of the post, which must be fully qualified and URL encoded. The end result HTML needed is something like this

grafti cms1

Using the Graffiti control panel, you can customize views for different areas of your blog very easily. Go to the Presentation tab from the main Control Panel screen, then Themes, and then Personalize. From there you can select a view to edit and start editing. In my case, I’m editing post.view, which looks something like this (click to enlarge):

grafti cms2

Notice that you can mouse over the items at the top of the edit screen, to see what properties they have. The obvious one I needed was $post.Url. What I really needed, though, was something like $post.UrlEncodedFullUrl, because $post.Url uses a non-encoded, relative path (e.g. /blog/post-name/). Further, the current version of Graffiti doesn’t expose the necessary pieces of System.Web to UrlEncode something, so I had to extend it myself.

Extending Graffiti

With a bit of help from ScottW, I wrote a Graffiti Extensions library to accomplish my task. It turns out that extending Graffiti is every bit as easy as I’d heard, so I was able to write my extension, deploy it, test it out, and get it 100% working in less time than it’s taken to write this blog post.

The short version of the story goes like this:

  • Create a class library that reference Graffiti.Core
  • Create a class and add the [Chalk(“SteveSmith”)] attribute to it
  • Create a method Encode that takes and returns a string
  • Compile it and drop it into the /bin of your blog site
  • Edit a view and you can now use $SteveSmith.Encode($post.Url)

The slightly longer version:


using System.Web;
using Graffiti.Core;
namespace SteveSmith.GraffitiExtensions
    public class Extension
        public static string UrlEncode(string url)
            return HttpUtility.UrlEncode(url);
        public static HttpContext Context
                return HttpContext.Current;
         public static string FullUrl(string postUrl)
            return "http://" +
                 Context.Request.Url.Host +
                 VirtualPathUtility.Combine("/", postUrl);


using System;
using Graffiti.Core;
namespace SteveSmith.GraffitiExtensions{
    public class Promote
        public string DotNetKicks(string postUrl)
            string encodedUrl =
            string dnkFormatString = 
"<a href="{0}"><img src="{0}" border="0" alt="kick it on" /></a>";
             return String.Format(dnkFormatString, encodedUrl);

After compiling and deploying the code, I now have full access to HttpContext so I won’t run into this problem in the future. I also have a simple shortcut for creating DotNetKicks image chiclets, and I can add additional such things to my Promote class as needed for Digg,, etc. Creating such an image now requires the following code in my post.view:

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.


Copyright © 2021