print yarrr!

Webchick cornered me tonight and asked me to take a look at an interesting patch that affects themers: Allow more granular theming of drupal_rendered elements. The short version is that if the patch is applied all template files will need to be updated from:

print $content

to

print r($content)

The new "yarr" function will allow you to render the variable from within the template. This means you will be able to extract specific fields from the "whole" content variable and style them differently (y'know, like an image that ought to be floated to the right). It also means that you can actually use the variable $content instead of just chucking it and having to style each field individually because you want a variable to have a unique HTML wrapper/CSS style applied.

Overall I think the patch is a good suggestion. I have only one concern: print_r and print r are very different, but look similar. I'd hate to have to teach a class where I say, "print r" and explain why that is completely different and in no way related to "print_r."

Is this being too picky? What do you think? Please leave your comments IN THE ISSUE QUEUE and help make Drupal 7 even more awesome for themers and future themers! (And thanks to the developers for looking out for us.)

I'm new to PHP and Drupal,

I'm new to PHP and Drupal, so a lot of this goes over my head. But certainly, the ability to style individual fields would be ideal. One thing that worries me after reading the discussion page over on Drupal about this, is the mention of security issues to do with the current method of breaking up $content into its various components. I'm currently working on a Drupal 6 theme for one of my sites and really want to be able to do this, but obviously concerned about security issues. Can you recommend any good guides for avoiding security issues?

Why do we use print and not

Why do we use print and not echo? They're synonymous and echo is 1 character shorter (thus saving bandwidth on things like CVS checkouts ;-) hehe).


<?php
echo r();
print r();
?>

To me, echo r(); looks better...

well perhaps the person

well perhaps the person creating phptemplate engine originally was a c programmer.

also echo is a few cpu cycles faster because it doesn't return anything

but I guess that the little savings of this will not matter a lot
---
Internet Unlimited

I think it's a very good

I think it's a very good point. It seems trivial now but I can only imagine the headaches this might cause on the forums. I can see why it's "r" - you want a single-character function name, and one that stands for "render" seems right - but I think e() or n() might be just as good.

I didn't heard about yarr

I didn't heard about yarr function in Drupal yet,so thanks for this information.I hope we the Drupal users would take the advantage of this feature. zero gravity lounge outdoor chair

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <p> <span> <img> <blockquote> <b> <i>
  • Lines and paragraphs break automatically.

More information about formatting options