Hi,
OK, I am a Drupal developer. Several *maintained* thousands lines of code in CVS are mine. And I can't get this one -- it's driving me bananas.
I help people on a daily basis for my modules. Let's see if karma works :-D
The 'user' module has the function:
user_block()
If I call user_block('view',1) , an array with elements 'content' and 'subject.
HOWEVER. How do I get a *rendered* version of this block? The version with the right block around it, etc.
Right now, I am doing this but it's a little absurd:
I <?php global $user; if($user->uid != 0 ){ ?>
<?php $b=user_block('view',1);?>
<div class="block block-user" id="block-user-1">
<h2 class="title"><?print $b['subject']?></h2>
<div class="content">
<?print $b['content']?>
</div>
</div>
<? } ?>
This "simulates" what happens when you enable the block.
I searched the Drupal source code -- I am SUPPOSED to have a deep understanding of it.
But no. I couldn't find a better way to do this.
So... help?
Merc,
Comments
Is it that the block isn't showing up in the list of blocks?
Am assuming that your block isn't showing up in the list when you go to admin/build/block. Is that correct?
This question may sound remedial, but have you pasted this code into a new block? That is, if you want to have this show up as a block, go to admin/build/block and then click on the 'add block' tab, then paste your code and making sure you click 'php' for input format (under the text field). If you scroll down, you can find conditionals to have your block show up only on certain pages either based on path (works with pathauto) or by a conditional php script.
Please let me know if this is what you're getting at. You gotta talk real slow over here so we can understand you... :-)
The reason...
Hi,
The reason I want to show the block by changing page.tpl.php is because I want to display:
[The block -- IF the person is logged in]
Google ads
$left_column (all the blocks on the left hand side)
If I add "Navigation" in the l4ft column block (which I can), it will appear underneath the Google ads (that is, it will be invisible).
This is working right now in Free Software Magazine (with my ugly hack, see my original post). http://www.freesoftwaremagazine.com .
So yeah, the block is definitely showing up. But that's not what I want.
I could create a whole bloody region just for this:
$left_column_before [Containing the navigation block, with the conditional]
Google ads
$left_column (all the blocks on the left hand side)
But it seems like a BIT of an overkill, if you think that all will ever want is publish the *one* block up there.
I *could* paste the block in a hand-made block, with the PHP option. But, if I do that the class won't correspond to the "right" one of the admin block, which is a pain.
Does this make sense? Or does it show a little too much that I'm a developer?
The resolution?
This is quite an old post now, and I'm not a Drupal developer (although I am a PHP developer) and I think all you need to do is use render()
I tried this:
print render ($page['sidebar']['search_form'])and it worked fine, except, of course that the search form now appears twice, because I'm rendering the whole sidebar later on.
So to get around that I would probably create another region for template specific rendering, I get that in your case it would only have one block in it, but it may be useful.
I guess, if your against that, you could remove the block from the $page['sidebar'] array and render it separately.
Or maybe I misunderstood your point?
super!
your're the man! thats it what i was looking for.