Writing Your Own Chalk Extension

While we believe we are providing you with just about everything you need to build and design a great site out of the box, we still wanted to make it really easy to plug your own code into Graffiti.

Extending Chalk is very simple.

  1. Add a reference to Graffiti.Core.dll
  2. Add the ChalkAttribute to the class you wish to expose. You must give the Chalk item a name.
  3. Drop it in your web site bin directory. At runtime Graffiti will do the rest.

Here is an example that enables the theme developer to quickly add links to a couple popular bookmarking sites as well as making it very easy for users to email the post to a friend.

[Chalk("shareIt")]
public class ShareIt
{
    public string HTML(string message, Post post)
    {
        return
            string.Format(shareItBody, 
                message, 
                HttpUtility.HtmlEncode(post.Title), new Macros().FullUrl(post.Url));
    }

    private static readonly string shareItBody = "HTML TRUNCATED FOR DEMO";
}

After the class above is compiled and the assembly is added to your bin directory, you can then use it in a post list (index.view/etc) or on a single post view (post.view) with the following format: $shareIt.HTML("Share This Post", $post).

A couple of other things to mention.

  • Only public methods are exposed.
  • Only public properties are exposed. Fields will not be available, so you must use a "get".
  • Chalk extensions are not thread or request safe. You should NEVER store content or data locally.