This project has moved and is read-only. For the latest updates, please go here.

Macros Overview

Macros is a helper tool loaded by Graffiti on every page request.

Listed below are the available methods and properties.

CategoryLink(Category category)
Renders the full HTML for a category link.

Renders the comment submit button. This is a normal input button wired up to save the comment via Ajax.

CommentButton(IDictionary dictionary)
Same as above except you can add attributes (such as class) which get rendered with the button.

Renders the standard comment form. This form is pre-wired up to the Ajax button.

CommentLink(Comment comment)
Renders a link to comment. It will automatically grab the post and base the url off the post.url +

CommentUrl(Post p)
Takes a post and returns a url to the comments section of the post page. Usually just posturl/#comments.

CommentUrl(Post p, IDictionary dictionary)
Same as above, except you can add custom attributes. To change #comments you should add a property called “anchor”.

Renders the standard "Contact Us" form.

EditLink(Post post)
Renders a link to edit the post if the current user has the proper credentials.

FormattedDate(string dateTime)
FormattedDate(DateTime dateTime)
Gets the formatted date (from SiteSettings) for the datetime.

FullUrl(string absoluteUrl)
Converts an absolute url to a fully qualified url.

Renders the generator meta tag.

Renders the JavaScript elements all Graffiti pages rely on.

Gravatar(string email)
Gravatar(string email, IDictionary attributes)
Renders a Gravtar image element and safely handles users with no Gravtars.

Renders RSD, RSSAutodiscovery, GraffitiJavaScript, MetaTags and Generator (i.e., replaces the need to call the RSD, RssAutodiscovery(), GraffitiJavaScript, and Generator methods).

Image(string file)
Renders an image from the current theme.

IsNull(object obj)
Returns true if the item supplied is null or if it is a string and is empty.

Image(string file, IDictionary id) (note: see below for IDictionaries)
Renders an image from the current theme and renders any additional parameters as attributes on the image tag.

LoadThemeView(string file)
Renders the results of the view specified in the file name property. The file must be in the current theme.

Renders the Graffiti logo.

Pager(string cssClass)
Renders a pager for the current list of posts.

Pager(string cssClass, string previousText, string nextText)
Renders a pager for the current list of posts. Specify the text for Older Posts and Newer Posts links.

Renders the MetaTags for the site, category, or page. This method is not usually called directly and is part of the Head() method as well.

Renders the smart (dynamic) navigation bar as an unordered list. If the item on the navigation bar matches the current requested url, it will have a CSS class applied called "selected".

NavigationSubLinks(bool usePostsIfNoChildCategories)
Creates a list of links which can be used to build custom sub category navigation. Specify whether posts from the category should be returned as links if there are no child categories.

QueryString(string key)
Returns the value of the specified query string from the url, for example q may return search string and p may return a page number if those values are present in the url.

RandomImage(string path, string pattern)
Returns a random image matching the pattern parameter for the current theme.

Reflect(object obj)
Renders the public properties of any object. You can use this to figure out which properties Graffiti exposes.

Reflect(object obj, bool showTypes)
Same as above, except you can optionally request the .NET type values for each property to be rendered.

RightSideBar(IDictionary dictionary) LeftSideBar(IDictionary dictionary)
Renders the widgets for the selected sidebar. You can specify the beforeWidget, afterWidget, beforeTitle, and afterTitle HTML.

Renders the RSD link element (Good for Metablog client support).

Renders the RssAutoDiscovery for the root site and optionally for the current category or tag. Also handles FeedBurner support.

Returns the current search querystring (Request.QueryString“q”).

Renders an image with a spinner image.

Displays an unordered list of subcategories when a parent category is selected.

Style(string file)
Renders the style sheet element for the file name. The media is set to sheet.

Style(string file, string type)
Renders the style sheet element for the file name and allows you to specify the media type.

TagCloudUL(int min, int max)
Renders a tag cloud. Min is the minimum number of posts a tag must be found in. Max is the maximum number of tags to return. You must add the UL tags.

TagList(string listOfTags)
Take a comma separated list of tags and renders “Tagged as:” and then displays each tag name as a link.

TagList(string listOfTags, string desc)
Same as above, except instead of “Tagged as”, the value of “desc” is used.

ThemeFile(string file)
Returns the absolute path of the file name in the current theme.

TruncateHTML(string html, int len)
Safely truncates a block of html and wraps it in paragraph tags.

Renders each top-level category as a link surrounded by li elements. It is up to you to add the UL tags.

ULPostsInCategory(int categoryId)
Renders an unordered list containing the last 5 posts in the supplied category.

ULRecentPosts(int numberOfPosts)
Renders the numberOfPosts recent posts as a link surrounded by li elements. It is up to you to add the UL tags.

ULRecentComments(int numberOfComments)
Same as above, except for comments.

Widget(string title, string beforeTitle, string afterTitle, string beforeContent, string afterContent)
Renders a widget by its title. The widget does not have to be assigned to a side bar in order to be displayed. You can specify the beforeContent, afterContent, beforeTitle, and afterTitle HTML.

Last edited Nov 18, 2010 at 7:33 PM by jkillebrew, version 8


jkillebrew Apr 11, 2010 at 7:23 AM 
The EditLink macro should look like this: $macros.EditLink($post)
but it will ONLY be visible to a user logged in and with edit rights allowing that post to be edited, otherwise it is not rendered at all.

Jkenny81 Apr 10, 2010 at 8:13 PM 
Can someone give me an example how to use the EditLink(Post post) macro? I can't seem to get it to work.