In the body of a block I am writing php code to display 2 different versions of content, developer/production.
I would like to echo the block's title into the contents, but I am new to Drupal and don't know what variable to use or where to look for this documentation?

All I could find was $block['title'] and this doesn't output anything - as below. (using Drupal 6.6)

eg. I write..

<?php if (strpos($_SERVER['HTTP_HOST'], 'dev.') === 0) { ?>

<div style="width:160px; height:600px; border: 1px red solid; color: red; text-align: center">
<?php echo $block['title']; ?>
</div>

<?php } else { ?>

Output Adsense code here

<?php } ?>

Comments

yuriy.babenko’s picture

You can use get_defined_vars() to get a list of all defined variables and then find what you're looking for:

echo '<pre>';
print_r(get_defined_vars());
echo '</pre>';

---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

behindthepage’s picture

Very curious. I did a few experiments on a fresh 6.6 install and it looks like $block is not available from within a block. I don't know why, I have a suspicion that it used to be.

You could probably do this is in a custom tpl file for that block.
More Info http://drupal.org/node/104319

I see you are in Australia. I'm in Sydney, where are you?

Regards
Geoff
gpd_in_oz
"Everything should be made as simple as possible, but not simpler." - Albert Einstein

Regards
Geoff

frontierfox’s picture

Thanks for the get_defined_vars() tip, I am brand new to PHP & Drupal, but have been programming for 15+ years. ;-)

Unfortunately the text for the block title was not found in the defined vars, so I guess that means it is a no-go for now?

Could defintely see this done as a custom block, but I haven't started customizing my templates yet. That whole aspect of Drupal impresses me to no end I tell you! :-) (that is the way you override really specific content with functions in the templates - WOW!)

What I was trying to acheive is to not show my Adsense ad's to myself while developing & friends IP's who I can't trust not to click. That was easy, so today I had the idea to put in red box fillers where the ad's appear instead of just nothing. So then I though it would be the icing on the cake to be able to write out the module title instead of just static 'ad goes here'. But I can certainly make do with just static text.

Geoff: I am in Melbourne.

http://buygreen.com.au - Go Green Australia | http://t5lighting.com.au - Energy efficient fluorescent lighting

yuriy.babenko’s picture

That's strange...

Try $subject.

Alternatively, you can implement template_preprocess_block(&$vars) in your theme's template.php, and play with the subject (title) there. I know for a fact that it's available there, and it really should be in the block.tpl.php file, too. Take a look at the extended templating tutorial (link in my signature) for an example, although the implementation there has a bit of a different purpose.
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

frontierfox’s picture

No luck with the $subject var. I am thinking that it's probably not available in the block body because the PHP Filter doesn't know about it's context? ie. it could be fired from anywhere an input filter can be selected.

http://buygreen.com.au - Go Green Australia | http://t5lighting.com.au - Energy efficient fluorescent lighting

gforce301’s picture

AFAIK the 'title' of a block was never available in the 'body' of the block that you would edit on the blocks admin page. However, you could implement a block template for your block and then all of the information of the block is available.