Hooks

Making a custom block with an admin settings form in a Drupal module

Often while building a Drupal website, you'll need to create a custom Block containing HTML and content. Completely standard right? It's a problem when your client or the site maintainer needs to change some of that content. They are forced to wade through significant amounts of HTML to find that little bit of content to update. Instead, why don't you build a custom settings page? Your site maintainer gets a simple form to update and you get variables to output.

Using theme hooks to display a tpl.php on a menu path

The Node, Views and Panels modules can (and should!) handle most pages you need on a site, but sometimes you need complete control of a "hard coded" content area. You could create a new Page node with a Full HTML text format. Instead, how about putting the whole thing in code? Your work will be in version control and much more straightforward to maintain. Imagine editing HTML in a text editor rather than in the Drupal admin! So much better.

Render/embed a Panels Page in a jQuery Dialog Box

I need a page on my Drupal 7 project site to display within a jQuery modal dialog box. Adding content to a jQuery dialog is straightforward with the Dialog module. The issue was the dialog box needed to contain the contents of a Panel. Previously I've embeded Views using views_embed_view(), but I've never tried to embed a Panel. A web search wouldn't give me a quick answer, so I worked it out.

Change Image Style and Row Class depending on result count

This is a simple example of the use of Views hooks in the template.php file of a theme. It is written for use with Drupal 7 and Views 7.x-3.0-beta3. 

In this project, a page contains a View which must display one, two or three results/rows. Each row contains an image and and body text. The final output display must to stay roughly the same size regardless of the amount of content. To make it all fit and allow for custom theming/CSS, I decided to change the Image Style and Row Class depending on the number of results.

Subscribe to Hooks