Just A Summary

Piers Cawley Practices Punditry

Cunning Typo Sidebar Tricks

If you’re reading this on the website rather than through a feedreader and you look to the left you’ll see either a bunch of links to cited books or an Amazon ‘self optimizing links’ banner (though, if it keeps ‘optimizing’ like it has being I’ll be changing it to something else). This is implemented using a mildly hacked version of the standard typo amazon_sidebar plugin.

“But,” I hear you say, “The sidebar’s over on the right, and Typo can only support one sidebar.”

And you’re right, Typo’s admin interface can only handle configuring one sidebar, and I’m not entirely sure how to make it work with too – hopefully our new maintainer and usability advocate, Frédéric de Villamil has some ideas along those lines. So, how does it work.

Let’s take a look at a fragment of my layouts/default.rhtml file shall we?

The thing about Sidebar objects is that there’s no real need to store them in the database. It’s done as a convenience so you can manage them through the admin interface, but if you want to use a sidebar widget anywhere in your layout there’s nothing stopping you.

Actually, that’s not quite true, before revision #1407, the render_sidebars helper couldn’t take an argument, so you had to jump through a bunch more hoops, but (as you’ll see if you follow the link), the code change is trivial, if you need the functionality but don’t want to move to an SVN version of typo you can just change that one helper. The change should work in any Typo newer than about 8 months old, and the underlying idea should work with much older version too, you’ll just have to think a bit harder to apply the patch.

Published on Sat, 14 Apr 2007 03:36:16 GMT by Piers Cawley under .

If you liked this article you can add me to Twitter
  • Gravatar

    By Ian Serlin Sat, 12 Jan 2008 20:38:19 GMT

    This is how I got the category sidebar to render properly anywhere in the page:

    <%= render_sidebars CategorySidebar.new :count => false %>

    As you can see, there is no comma or other delimiter between the sidebar object you want to create and the options that it takes.

    The name of the sidebar object to create (in this case “CategorySidebar” as well as the list of options for that sidebar object currently appear in the /vendor/plugins/_sidebar/lib/_sidebar.rb file.

    For the CategorySidebar, we have the following 2 lines:

    setting :count, true, :label => ‘Show article count’, :input_type => :checkbox

    setting :empty, false, :label => ‘Show empty categories’, :input_type => :checkbox

    letting us know that CategorySidebars can optionally take two arguments, :count and :empty. These are the same options you would see in the Admin interface to typo, but you wouldn’t necesarrily know what they were programmatically called without looking in the /lib/*_sidebar.rb file.

    Hope this comment helps you out! To see this in action you can go to www.disruptian.com , the menu in the top left is actually the CategorySidebar.


    Ian Serlin

  • Gravatar

    By ning Thu, 09 Oct 2008 11:20:20 GMT

    where is the render_sidebars method define?

Comment Cunning Typo Sidebar Tricks

Powered by Publify – Thème Frédéric de Villamil | Photo Glenn