18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Theming a <strong>Module</strong><br />

Now that you've learned the architecture of the theme layer, let's put that knowledge<br />

to practical use. In this chapter, we'll write some real code that both uses existing<br />

theme implementations and builds new theme implementations.<br />

While the previous chapter was a whirlwind tour of the theme layer, this chapter<br />

will be a more thoughtful exploration of the system and how to best use it. We'll<br />

touch on the following ideas:<br />

• The advantages of being lazy by reusing code<br />

• Finding and reusing a theme hook<br />

• Attaching CSS to render elements<br />

• Creating stylesheets for RTL languages<br />

• Building a theme hook<br />

To help us learn these points, we're going to build a simple module in our examples.<br />

<strong>Drupal</strong> comes with the blog module, which creates multi-user blogs, one for each<br />

user and one aggregate blog. However, many websites only need a single blog. We're<br />

going to re-create some of the functionality of the blog module, and re-purpose it<br />

for a single blog that uses <strong>Drupal</strong>'s default article content type. If you try out this<br />

chapter's code, you should disable <strong>Drupal</strong> 7's blog module first.<br />

Reusing a default theme implementation<br />

Now the first question you need to ask is "Should I reuse an existing theme hook or<br />

build my own?" Code reuse is one of the virtues of a lazy programmer. So the answer<br />

to that question is "Yes, be lazy!"

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!