Drupal 7 has an amazingly granular templating system that means each bit of the hierarchically structured page data can have its own template. After spending a long time understanding this I set to work on my first task.
I wanted a pull-out quote on some pages that integrates with the main layout - I don't just want it stuck in the main page content area block. This means that when it's used, I want it to interrupt the sidebar's content, to demand the attention that I have decided it deserves.
Simple, eh?
So I created a new text field on the page content type, and hid it from normal display (don't want it in the body). Ok, easy.
Now fields templates are rendered inside of node templates, inside of the page template. But I want to reach down and elevate a lowly field to present it in the main page template. I read various solutions, including an exemplary Drupal solution that suggests "all" one has to do is install the views module, configure a view, create a new block from the view, position the new block and... yes, I gave up (not least because Views wasn't functional in D7 at the time).
Positioning a tiny lump of html cannot be this difficult.
To my relief, it turns out that it's not difficult at all, it's just putting this in the template:
print $node->field_pullout[ $node->language ][0]['value'];
Hint: D6 users all across the world seem to be tripped up by the first index on field data (language). Confused me, too, when I was looking at the output of print_r($page)
- I could see what I wanted, but what was 'und'
? Would it change? Was this a reliable way to access the data? Well, yes, 'und' is D7's shorthand for undefined (although, clearly it is defined as en_gb, but hey).
Thanks to JochenJung over at Stack Overflow for the pointer.
I wanted pull-out quotes to stand out to give them higher visual priority.
If you're reading this, it worked! If not, then at least you didn't notice...