This project has moved. For the latest updates, please go here.

Extending Chalk

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

You can extend Chalk by doing the following:
  • Adding a reference to Graffiti.Core.dll
  • Adding the ChalkAttribute to the class you wish to expose. You must give the Chalk item a name.
  • Dropping 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 of 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 is compiled and the assembly is added to your bin directory, you can 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).

There are a couple of other things to mention about extending Chalk.
  • 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.
You can view an example here.

Last edited Mar 31, 2010 at 4:51 AM by jkillebrew, version 1

Comments

No comments yet.