Print Chatbox Block?
JonGirard - January 18, 2008 - 01:41
Hi All,
I'd like to, using php print the block for my chat box module onto my frontpage. I don't want to use the pre-defined region settings (content, header, footer, left sidebar..etc) options because I want this block to appear inbetween some divs I have placed in my page.tpl.php file.
So is there someway using print code to print the module onto the page in the desired location?
A snippet from my page.tpl.php file:
<?php print $content; ?>
<div id="lowersection">
<div id="comment-box"><div id="comment-box-header"><h2>Fresh From The Members:</h2></div>
<div id="submitted-comments"> PRINT THE CHATBOX MODULE RIGHT HERE </div>
<div id="submit-comment"></div>
<div id="login-form-variable"><form action="/drupal5.6BDC/?q=user" accept-charset="UTF-8" method="post" id="user-login-front"><input name="edit-name" type="text" id="edit-name" value="Username" /><input name="edit-pass" type="password" id="edit-pass" value="password" /><input type="image" src="sites/all/themes/BDC/proceedarrow.png" alt="Submit"></form><script type="text/javascript">SetHandlers()</script></div>
<div id="login-panel"><script type="text/javascript">$('#login-panel').slidePanel({status:'closed', target:'#login-form-variable'});</script><img src="sites/all/themes/BDC/loginbtn.png"/></div>
</div>
</div>
</div>
<?php ?>Any help is appreciated. This chat is gonna be the feature thing on my site!
Jon.

Ok. So I got the printing of... *???*
Ok. So I got the printing of the block figured out.
<?php$block = module_invoke('chatblock', 'block', 'view', 0);
print $block['content'];
?>
When the user is logged in (and only when the user is logged in, otherwise the script will give errors, because the post feature is disabled when logged out) I need this to be printed along with the chatblock.
<script type="text/javascript">
var chatBlockInterval;
var chatBlockUpdateURL = "http://localhost:8888/drupal5.6BDC/?q=chatblock/update";
var chatBlockViewURL = "http://localhost:8888/drupal5.6BDC/?q=chatblock/view";
$(document).ready(function () {
chatBlockInterval = setInterval("chatboxGetMessage()", 5000);
chatboxInitScroll();
});</script>
Is there such a way to print this on the front page ONLY WHEN A USER IS LOGGED IN?
Jon.
couldn't you just add the
couldn't you just add the javascript to your page.tpl.php file, and then restrict the block to registered users? I'm not sure if you can use php to print out javascript...maybe echo would be the option. But I'm guessing that if you just put the code in the template file, and only show the block to registered users, it might work for you.
Can be done with this code:
Hi Brad,
Thanks for your reply. As it turns out, it does seem that you can use some php code in the head section to only allow javascript to be outputted for authenticated users.
This code works perfectly for me:
<?php
global $user;
if ( $user->uid ) {
// Logged in
?>
<script type="text/javascript">
var chatBlockInterval;
var chatBlockUpdateURL = "http://localhost:8888/drupal5.6BDC/?q=chatblock/update";
var chatBlockViewURL = "http://localhost:8888/drupal5.6BDC/?q=chatblock/view";
$(document).ready(function () {
chatBlockInterval = setInterval("chatboxGetMessage()", 5000);
chatboxInitScroll();
});</script>
<?php
}
?>
Thanks for your reply. Only displaying the block to users would have also most likely done the trick.
Jon.