Data is a built-in Chalk extension, similar to Macros, which enables quick and easy access to additional Graffiti data.
To use the data extension commands, just type $data and one of the methods listed below.
Categories()
Retrieves a list of all top level categories sorted alphabetically.
Featured()
Retrieves the site's featured post. It will return null if no Post is found. You may want to use this with $macros.IsNull.
Example:
#set($featuredPost = $data.Featured())
#if($macros.IsNull($featuredPost))
<h1>No featured post was found</h1>
#else
<h1>Featured: <a href="$featuredPost.Url">$featuredPost.Title</a></h1>
#end
Featured(int categoryId)
Retrieves the featured post for the category id. Just like Featured(), this method may return a null value. See example above.
GetPost(int id)
Retrieves the specified post.
PopularPosts(int numberOfPosts)
Retrieves a list of the sites most popular (by views) posts.
PopularPosts(int numberOfPosts, int categoryId)
Retrieves a list of the sites most popular (by views) posts for the category id.
Query(IDictionary parameters)
Allows you to query for specific content. At this time only posts are supported.
Example: Return the top 5 posts, regardless of category and order by Views Descending:
<ul>
#foreach($px in $data.Query(”%{top='5', orderby='Views DESC'}”))
<li> <a href=”$px.Url”>$px.Title</a></li>
#end
</ul>
Parameter Info:
RecentComments(int numberOfComments)
Retrieves a list of recent comments.
RecentComments(int numberOfComments, int categoryId)
Retrieves a list of recent comments from the category id.
RecentPosts(int numberOfPosts)
Retrieves the most recent “numberOfPosts”
RecentPosts(int numberOfPosts, int categoryId)
Retrieves a list of recent posts from the category id.
Tags(int min, int max)
Retrieves a list of tags. Min is the minimum number of posts a tag must contain. Max is the maximum number of tags to return.
Developer Tip: You can use the Data helpers above when you are writing Widgets, Chalk extensions, and Plug-ins for Graffiti. The object is found at Graffiti.Core.Data.