Subscribe via RSS

Sidebar Helper for CakePHP

Note: This article has been submitted to the Bakery, but it’s been pending approval for a couple of weeks now and I got bored of waiting, so I’m just posting it here. I will update with the Bakery link if/when it goes live!

Despite having written several bits of potentially re-usable code for my Cake apps over the years, this is the one that’s really stuck out with potential to become popular and useful to the masses. It’s been in action for years on Simon’s FFL, and more recently on Covers.FM, but a recent question on Stack Overflow prompted me to polish it up, document it and release it. It also gave me a chance to try out GitHub, which seems to be what the cool kids are using to publish/share/collabrote on code these days.

In a nutshell, the Sidebar helper allows you to insert a sidebar with multiple content blocks into your layouts, similar to Wordpress widgets.

So, without further ado, here’s the GitHub link:

http://github.com/ebotunes/cakephp/blob/a08a2011246a256fa1425bf07c98ff064436d527/helpers/sidebar.php

The code comments contain examples of usage to get you started. Technically speaking this doesn’t need to be used as a Side Bar – it ultimately depends on how you render the layout with CSS.

[I'll hopefully update this post with screenshots and sample CSS at some point when I've got more time. Just wanted to get the main code out there for now]