Question for drupal themers

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
User offline. Last seen 21 weeks 6 days ago.

Drupal themers, can I take a moment to pick your brains. I'm working on the drupal 7 codebase and am looking for some feedback. The less you know about PHP the better in this case.

Currently, in drupal if you want to display the right sidebar you would put something like:

<?php print $right ?>

in your page.tpl.php file.

What do you think about this changing to something like:

<?php print $region->right ?>

Additionally, would you find value in regions being available in other template files like the node.tpl.php file and views templates?

This is a color of the bike shed conversation. Please let me know your opinion.

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

G&G Moderator
Josiah's picture
Joined: 12/20/2007
User offline. Last seen 15 weeks 3 days ago.
Region Provides Some Context

I like associating the word right with region. Otherwise, it is a little too ambiguous. Right what? I don't know? Oh the right region! What's a region? At least I'm started in the correct direction and have something to look up. The word "right" is an impossible search term.

G&G Moderator
G&G Podcast Host
micah's picture
Joined: 06/21/2007
User offline. Last seen 2 weeks 3 days ago.
re: Region Provides Some Context

I agree with Josiah. $right is pretty ambiguous. Adding the $region to it would make a lot more sense. I felt pretty uncertain about the whole thing the first time I made new custom regions for the front page of a site. Part of it was wondering if my new region name would step on any existing variable names. (Like what would happen if I called a region $head for instance? Or something even more stupider.) Referencing them as $region->name could add a layer of safety as well as clarity.

Micah

Joined: 12/19/2008
User offline. Last seen 2 years 34 weeks ago.
Yeah. I'm pretty new to

Yeah. I'm pretty new to drupal themeing and php in general. Having to call the region first would make it easier to read the code and understand the call for noobies like me.

Joined: 12/07/2008
User offline. Last seen 1 year 46 weeks ago.
I'm new to theming and would

I'm new to theming and would agree that being more specific about what is being called (in this case the region) would be much more intuitive than how it currently is. Go for it!

-
David Needham
EnjoyCreativity.

Joined: 12/16/2007
User offline. Last seen 27 weeks 6 days ago.
Reads more like english to me...

I don't know squat about php, so I'm exactly what you're looking for, matt!

I like the change, because it reads more like English, with a noun, a verb and an adjective:

<?php
 
print //Verb
 
$region->right //Noun->adjective
?>

Print is your verb. Print what? $region (noun), then you modify the noun with an adjective for greater specificity. The region called right.

Its like saying: Fetch. Fetch what? Fetch the slipper. Which slipper? Fetch the red slipper.

Anyway, it's easier to read cause its structured more like language.

Blessings,

Yes!

I've done a fair bit of theming, and I still think that the first idea is a great one.

As for getting regions in node templates, I'm not so sure that having that block of HTML available would be that useful. I've done things like that before - we used some custom regions output in node templates on the Bob Dylan site, but we just added it like so: $vars[$region] = theme('blocks', $region); (Drupal 5 example, obviously.)

My personal opinion is that the availability of regions in node templates by default might confuse beginners, since using regions inline in node content is a (to my mind) pretty advanced theming technique. It's usually pretty tough to relate the concept of blocks vs. the main page content (which could be a node, or a view, or output from a module, etc.) to novice Drupal users, and I fear that having regions readily available in node templates might make that steep learning curve just a bit more so. It's an easy enough call once you know a bit about phptemplate.

Does that make sense?

Joined: 04/19/2008
User offline. Last seen 2 years 24 weeks ago.
I'd certainly like to have

I'd certainly like to have regions available in templates besides page.tpl.php coded in the same format. That would be a theming-usability improvement in my opinion.

For instance in page.tpl.php I might use:
<?php print $my_region; ?>

Whereas in node.tpl.php I'd use the following (learned here):
<?php print theme('blocks', 'my_region'); ?>

I haven't tried in a View, so I'm not sure if that would be yet another bit of code to do. So, it would be nice if there was one standard way (assuming it didn't impact performance at all, since I'm rootin' for a speedier D7 haha) to call up a region no matter what template you're working in. For instance I couldn't recall the region code for using in the node template without double checking a pre-existing template where I had used the code before.

So far as $region->right ... I think that does have some inherent "clarity improvement" built in (at a little cost of complexity), since unless I know better, $right is just some variable from who knows what (I know it means the Right region, but maybe someone else may not, or get it confused with other PHP variables that are embedded in the template).

Joined: 11/28/2008
User offline. Last seen 28 weeks 5 days ago.
I'm all for associating

I'm all for associating different regions with one $region variable/object/whatever it is.

I'm also all for making regions available to different .tpl.php files. I recently had to make a custom region available to the node template - took me ages to find out how to do it, and even then it wasn't as easy as it should be.

Yay for simplicity!