Just A Summary

Piers Cawley Practices Punditry

Cunning tricks with the new typo sidebars

Posted by Piers Cawley Sun, 20 Aug 2006 09:18:00 GMT

I was going to save this until I’d rejigged my blog to a three column layout and had left everyone mystified by how I’d managed to get sidebars on both sides. But, let’s be honest here, it’s going to be ages before I do that. So, I shall spill the beans preemptively.

Actually, you’ve been able to do this, or something like it for ages, but new style sidebars make it easier.

Imagine you’re editing the layout of your new, three column theme, and you’ve got a left-sidebar div, which you want to populate with a tag cloud and the categories sidebar.

<div id='left-sidebar'>
<%= render_sidebar TagSidebar.new :maximum_tags => 30 %>
<%= render_sidebar CategorySidebar.new :show_empty_categories => false %>
</div>

Then it’s just a matter of styling to get the sidebar in the right place.

This works because the vast majority of sidebars don’t hold any state apart from their settings (Certainly none of the core sidebars do) and their position in the sidebar list. So, if you want to render particular sidebars in your layout, you don’t need to go to the database at all.

Of course, I can conceive of sidebars that will need to manage persistent state, but now I’ve realised that you can manage sidebars like this without having to go to admin/sidebar at all, I shall be working on making things a little bit friendlier. If nothing else, I should probably write a helper that lets you do:

render :sidebar => TagSidebar, :maximum_tags => 15

to make the interface a little more consistent with the rest of rails’ suite of render helpers.

Enjoy.

Update

  1. Now that extended content is working properly again, I’ve moved the details back below the fold.
  2. Dan Milliron has another neat way of doing this.
Comments

Leave a response

Comments



Just A Summary