Hi !
I'm not really good at php but i want to try achieving this :
We have a moodle site that updates information in blocks such as latest news and upcoming events etc.
I want to create a simple php / html page , that can display the news block or any block of choice where ever i want in the page. Instead of using iframes, i would like to integrate the php code of the block to display - into the new page i'm creating. If that requires including some moodle files, thats ok
Has anyone tried this before ?
I'm looking for something like that too... (see in my profile->forums)...
Hi
You can start here: http://docs.moodle.org/en/Development:Blocks
May the example is not exactly what you need but it is also very helpful.
Ângelo
You can start here: http://docs.moodle.org/en/Development:Blocks
May the example is not exactly what you need but it is also very helpful.
Ângelo
Hi Ângelo,
Thanks for the link. Actually, two days ago i write my first block by following this link. and it works good. It produce something like that
The next step i would like to improve this block to something like that
(for example):
where "News block" means the existing block that prints the latest knews.
Thanks for the link. Actually, two days ago i write my first block by following this link. and it works good. It produce something like that
header herer |
"hello word" |
footer her |
The next step i would like to improve this block to something like that
(for example):
header here | |
News block here | "hello wordd" |
footer here |
Have you looked at the Flexible Page format (http://www.moodlerooms.com/intel.html) that Michael Penney has done? While you are still limited to three columns, you can make them all equal in size and place a block anywhere on the page, even in the center. It may be worth looking at.
Thanks,
Matt
Thanks,
Matt
Hi Matt,
I saw the Page format, and installed it. I can put my blocks or modules anywhere
i want. But the problem for me is that :
1=> i created a module named "newmodule"
2=> and i can add it in course as an activity.
3=> On i'm in the course and i click the newmodule link, it display the newmodule content witch is a flash video with an into (all in one column).
4=>So, what i'd like to to, is displaying other blogs in the content of my newmodule. I Think i could this with the page format, but in that case i'll have to rewritte all the template because i'm using a custom prety nice template.
In add, i would like to create php page from scratch, and put existing block (if neede).
For more information here a simple php page i'm writting:
1-Step1 : display a simple message like "hello word"
<?php
require('config.php');
require_login();
$user = get_record('user', 'id',$USER->id); /// Getting a record from a db table
if ($user) {
echo "hello word";
} else {
error('Bad....');
}
?>
This script works and displays "hello word" on the screen.
2-Step2 : adding "login block"
I tried these methodes without any success
$mybloc = block_instance('login').
$mybloc->get_content();
and
$myblock = new block_login();
$myblock ->_load_instance(1); //1 referes to instance n°1
$myblock ->get_content();
does anyone can give an idea?
thanks
I saw the Page format, and installed it. I can put my blocks or modules anywhere
i want. But the problem for me is that :
1=> i created a module named "newmodule"
2=> and i can add it in course as an activity.
3=> On i'm in the course and i click the newmodule link, it display the newmodule content witch is a flash video with an into (all in one column).
4=>So, what i'd like to to, is displaying other blogs in the content of my newmodule. I Think i could this with the page format, but in that case i'll have to rewritte all the template because i'm using a custom prety nice template.
In add, i would like to create php page from scratch, and put existing block (if neede).
For more information here a simple php page i'm writting:
1-Step1 : display a simple message like "hello word"
<?php
require('config.php');
require_login();
$user = get_record('user', 'id',$USER->id); /// Getting a record from a db table
if ($user) {
echo "hello word";
} else {
error('Bad....');
}
?>
This script works and displays "hello word" on the screen.
2-Step2 : adding "login block"
I tried these methodes without any success
$mybloc = block_instance('login').
$mybloc->get_content();
and
$myblock = new block_login();
$myblock ->_load_instance(1); //1 referes to instance n°1
$myblock ->get_content();
does anyone can give an idea?
thanks
In reply to Anil Sharma
Re: How to create HTML page with moodle blocks ? my solution
by Hassani Hachim -
Hi,
I created a php page, here is the code :
<?php
require_once("config.php");
//require_once($CFG->libdir.'/blocklib.php');
require_once($CFG->dirroot .'/lib/blocklib.php');
require_login();
print_header( 'My Page Title1',
'My Page Title2',
'My Page Title3');
//---------------------------------------------------
$CFG->showblock=1;
$inme=me();
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\">";
}
if($CFG->showblock==1){
echo "</td></tr></table>";
}
$CFG->showblock=0;
//----------------------------------------------------
print_footer();
?>
And it produces (see the image) :
I created a php page, here is the code :
<?php
require_once("config.php");
//require_once($CFG->libdir.'/blocklib.php');
require_once($CFG->dirroot .'/lib/blocklib.php');
require_login();
print_header( 'My Page Title1',
'My Page Title2',
'My Page Title3');
//---------------------------------------------------
$CFG->showblock=1;
$inme=me();
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\">";
}
if($CFG->showblock==1){
echo "</td></tr></table>";
}
$CFG->showblock=0;
//----------------------------------------------------
print_footer();
?>
And it produces (see the image) :
