VanillaForums.com Upgrades and Theme Hooks

2 minute read

December 19, 2009

VanillaForums.com Upgrades and Theme Hooks

This morning we pushed a tiny change to GitHub that is really only three lines of code, but affects the abilities of Vanilla in an incredible way: Theme Hooks. The idea came to us this week when one of the community members explained how they were working on a theme that displayed part of the first comment in a discussion right on the discussion list. The discussion list doesn’t provide that field, so the theme author was writing ajax into his theme so he could pull the data from outside of the page and place it there. Obviously this is an immensely innefficient method to displaying data. What he really should have been able to do was alter the discussion query so that it gets the field he requires all in the same query.

The problem was that themes were essentially just html, css, and inline javascript – nothing more. In order to change the query to get that extra field, he would either have to write a sister plugin that would get the data and must be enabled in order for the theme to look right – or do his method of querying a separate page to get the data for every single discussion on the page. It just didn’t make sense to us that themes don’t have the ability to change the applications in a more effective way. So, it dawned on us that if themes had a pluggable hooks file just like applications do, they would be able to plug into the applications in truly infinite ways. So, three lines of code later, themes are now pluggable – and our community member can remove a few hundred lines of javascript code in exchange for about ten lines of theme hooks.

It’s really simple to make your theme pluggable, just create a “hooks.php” file in the root of your theme folder and place a shell pluggable class in there, like this:

class ThemeHooks implements Gdn_IPlugin {
public function Setup() {
return TRUE;
}
}

Then your theme can do whatever a plugin can do just by adding some methods to that class and hooking into the applications in any way you choose. Happy Theming!

News

Share Your Thoughts

Your email address will not be published.

Mark O'Sullivan

Written by Mark O'Sullivan

Have an Article for Vanilla's Blog?

Send us an email to [email protected] with your topic idea and we'll circle back with our publishing guidelines.

subscribe-1
Subscribe to the Community Corner Newsletter and get expert insight and analysis on how to get the most out of your online community every Friday.

    Request a Demo

    Schedule a product demo now.

    Contact Us