Asides with Habari

Tagged


So I thought I would outline the process I used to achieve the inline asides effect you are seeing on Sillyness. This was one of those moments where I just love how Habari handles things.

So lets set the stage


So this is what we are going to do. First we choose a tag that we will use to identify our asides. I chose "quickie". Once we have settled on a tag that will be used, we create at least one entry that uses the tag.


Once we have some content to test with, we move on to some PHP goodness. Habari returns an array of tags within the $post object. Normally we would make a call to the tags like so:


echo $post->tags_out; or echo $post->tags;


You will notice that there are two ways to call for your tags. We will be using both calls in this little tutorial. The first call gives you the tag array without any formatting filters applied. Habari allows you to create functions that interact with your content, in this instance if you wanted to do some extra formatting to your tags, you would write a function and call it like this:

Format::apply('my_function', 'post_tags_out');


Now anytime you call $post->tags_out Habari will apply your function to the tags before they are displayed. Very cool.


Now back to the task at hand. To style our "asides" posts differently we need to start our loop, and look through the tags array for each post and if we find our tag, in this case "quickie" we style the post differently. Here is the code to do just that:



tags ) ) { ?>


?php echo $post->title_out; ?> ยป content; ?> (comments->approved->count; ?>)




// We are seeing normal posts.


So, as you can see all we really have to do is call in_array(), pass it the tags array and the tag we are looking for and we are done.


You will notice that I am calling $post->tags, instead of $post->tags_out. This is important since we need an array to look through, not formatted text.


And that is it. With this code we have implemented inline asides. Pretty cool huh?