I need my block in all pages - mods

I need my block in all pages - mods

by Victor R -
Number of replies: 5

Is there any way to made appear my own block in all the pages of moodle?

I´m interested in show the block in all the mods

Thanks

Average of ratings: -
In reply to Victor R

Re: I need my block in all pages - mods

by Jan Dierckx -

Thanks to Jon's pagelib this is possible. Unfortunately up to now this has only been implemented in the quiz module and the chat module. You can have a look at the code of these modules. Some discussion and some other code examples are here

BTW I really like this new way of handling pages / tables (with the new tablelib and pagelib) Is there anything like this coming for forms as well? It would be nice to be able to add a form in the same manner. It would also make it easier to have a consistent user interface.

In reply to Jan Dierckx

My block in all pages - mods ALREADY POSSIBLE!

by Josep M. Fontana -
Jan and others,

See the message I posted at:
http://moodle.org/mod/forum/discuss.php?d=31917#148678

Joan Codina just created a floating toolbar which makes it technically possible to have a block (or something somewhat equivalent to a block) available from any mod or resource in a Moodle course.

Josep M.
In reply to Josep M. Fontana

It's really nice for floating toolbar... I found a simpliest way for statics

by Victor R -

Thanks all for your replies,

Both ways are very usefull, maybe the floating toolbar is more simply to implement.

but taking care of my needs (a static main block) into the mods and other extra pages i found this way that i hope be helpfull for you too.

In general terms I create a Theme where the system look in a simply list of files or directories, and if the page that I visit is into this list the main block (or all the blocks designed for the SITE) in the left side is automaticly loaded.

For 1.5 version

I atach you the code in PHP that you must add only in the header.html and footer.html files of your theme directory.

HEADER.HTML (at the Begin of the file)

//Must include the libs of blokcs  

require_once($CFG->dirroot .'/lib/blocklib.php'); 

HEADER.HTML (at the end of the file)

<?php

$CFG->showblock=0;
$inme=me();

//this is the list of files or directories where i want to sho my Blocks

//if you put a directory all the files inside it will show the blocks

$fblocks = array("/calendar/","/mod/","grades.php");

//Here I use a flag to know if I'm in a page or directory of the list

foreach ($fblocks as $fblock){
    if(ereg($fblock, me())){
        $CFG->showblock=1;
    }
}

if($CFG->showblock==1){

//Now I create a table for the main part of the page with two colums, one for the Block

//and other for the really content of the mod

  echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">";

  echo "<tr><td width=\"120\" valign=\"top\">";

//This is the first colum

//I Include my left Blocks

    $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
    $pageblocks = blocks_setup($PAGE);
   
    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
    }

//This is the second colum for the content of the mod
echo "</td><td valign=\"top\">";   

}

?>   
<!-- END OF HEADER -->

FOOTER.HTML (at the begin of the file)

<!-- START OF FOOTER -->
<?php

//If I put the Block in this page now I must close the table

if($CFG->showblock==1){
    echo "
</td></tr></table>";
}
$CFG->showblock=0;
?>

----------------------------- ooooooooo --------------------------

that's all, maybe I'll made a table in the database to customice the list of pages for the block.

If you have some question mail me, in English, spanish or catalan

Thanks all again. 

In reply to Victor R

Re: It's really nice for floating toolbar... I found a simpliest way for statics

by Josep M. Fontana -
Hola Victor,

What you suggest seems like a good solution for many scenarios. The problem is that, for the kind of tool we needed , it was necessary that the "block" was reachable anywhere (from within resources, for instance, not only from within activities/modules). That's why we opted for a different solution instead of using blocks. So in fact, what Joan has done should not be seen as an alternative to blocks but rather as a complement. If you read my last posting in the "developers forum", I explain that using the term "floating block" for our tool is misleading.

Keep us informed about your work. Expanding the domains where blocks can be used is, I think, something really necessary.

Josep M.
In reply to Victor R

Re: It's really nice for floating toolbar... I found a simpliest way for statics

by warmac - -
I tried that header/footer code but all I get is a blank page

I put the code at the very top and bottom of header and same with footer the top

is there anything I misssed ? root is correct too