Note: You are currently viewing documentation for Moodle 3.2. Up-to-date documentation for the latest stable version of Moodle is probably available here: Block layout.

Block layout: Difference between revisions

From MoodleDocs
 
(14 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Blocks}}
==Default block layout for new courses==
==Default block layout for new courses==


[[Sticky blocks]] may be used in Moodle 1.6.
To amend the default block layout for new courses, one or more of the following lines (omitting the forward slashes) from ''config-dist.php'' may be added to ''[[Configuration_file|config.php]]'', amending the block names as required.
 
Alternatively, to amend the default block layout for new courses (in all versions of Moodle), add one or more of the following lines (omitting the forward slashes) to ''config.php'' and amend the block names as required.
 
Note how the colon is used to separate those blocks appearing on the left, from those appearing on the right.


  // These variables define DEFAULT block variables for new courses
  // These variables define DEFAULT block variables for new courses
  // If this one is set it overrides all others and is the only one used.
  // If this one is set it overrides all others and is the only one used.
  //      $CFG->defaultblocks_override =    'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
  //      $CFG->defaultblocks_override =    'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
  //
  //
  // These variables define the specific settings for defined course formats.
  // These variables define the specific settings for defined course formats.
  // They override any settings defined in the formats own config file.
  // They override any settings defined in the formats own config file.
  //      $CFG->defaultblocks_site = 'site_main_menu,admin,course_list:course_summary,calendar_month';
  //      $CFG->defaultblocks_site = 'site_main_menu,course_list:course_summary,calendar_month';
  //      $CFG->defaultblocks_social =  'participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list';
  //      $CFG->defaultblocks_social =  'participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,course_list';
  //      $CFG->defaultblocks_topics =  'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
  //      $CFG->defaultblocks_topics =  'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
  //      $CFG->defaultblocks_weeks =  'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
  //      $CFG->defaultblocks_weeks =  'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
  // These blocks are used when no other default setting is found.
  // These blocks are used when no other default setting is found.
  //      $CFG->defaultblocks = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';</pre>
  //      $CFG->defaultblocks = 'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';</pre>
(code copied from ''config-dist.php'')
 
For example, to set the default block layout for topics format courses to People, Tags and Administration on the left, and Messages, Online users and Recent activity on the right, simply add the following line to your ''config.php'' file:
 
$CFG->defaultblocks_topics =  'participants,tags:messages,online_users,recent_activity';
 
Note how the colon is used to separate those blocks appearing on the left, from those appearing on the right and there is no space after each comma.


==Resetting the block layout for existing courses==
==Resetting the block layout for existing courses==
Line 25: Line 27:
The block layout for existing courses may be reset by copying the following script into a text file, saving it as ''resetblocks.php'', copying it into the Moodle root directory, then visiting <code><nowiki>http://yourmoodlesite.org/resetblocks.php</nowiki></code>.  
The block layout for existing courses may be reset by copying the following script into a text file, saving it as ''resetblocks.php'', copying it into the Moodle root directory, then visiting <code><nowiki>http://yourmoodlesite.org/resetblocks.php</nowiki></code>.  


'''Warning''': This script may change the layout of your course pages and also remove blocks from those pages if they have not been specified in the config.php line. Check which of your courses has blocks which are not in the config.pho line and be prepared to spend time adding blocks to your course pages again. ''Please note that a database backup is recommended before using the script''.
'''Warning''': This script may change the layout of your course pages and also remove blocks from those pages if they have not been specified in the config.php line. Check which of your courses has blocks which are not in the config.php line and be prepared to spend time adding blocks to your course pages again. ''Please note that a database backup is recommended before using the script''.


'''M2.2 and later:'''
  <?php
  <?php
//moodle 2.2+
  require_once('config.php');
  require_once('config.php');
  require_once($CFG->libdir.'/blocklib.php');
  require_once($CFG->libdir.'/blocklib.php');
  $courses = get_records('course');
  $courses = get_courses();//can be feed categoryid to just effect one category
  foreach($courses as $course) {
  foreach($courses as $course) {
     $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
     $context = context_course::instance($course->id);
     blocks_repopulate_page($page);
     blocks_delete_all_for_context($context->id);
}
    blocks_add_default_course_blocks($course);
print_heading('Done!');
}
  ?>
  ?>


==See also==
'''M2.0 to M2.2:'''
 
<?php
Using Moodle [http://moodle.org/mod/forum/discuss.php?d=98808 Default Block Layout for moodle 1.9] forum discussion
//moodle 2.0 - 2.2
require_once('config.php');
require_once($CFG->libdir.'/blocklib.php');
$courses = get_courses();//can be feed categoryid to just effect one category
foreach($courses as $course) {
    $context = get_context_instance(CONTEXT_COURSE,$course->id);
    blocks_delete_all_for_context($context->id);
    blocks_add_default_course_blocks($course);
}
?>


[[Category:Block]]
[[es:Diseño de bloque]]
[[ja:ブロックレイアウト]]
[[ja:ブロックレイアウト]]
[[fr:Disposition des blocs]]

Latest revision as of 16:40, 29 September 2016

Default block layout for new courses

To amend the default block layout for new courses, one or more of the following lines (omitting the forward slashes) from config-dist.php may be added to config.php, amending the block names as required.

// These variables define DEFAULT block variables for new courses
// If this one is set it overrides all others and is the only one used.
//      $CFG->defaultblocks_override =    'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
//
// These variables define the specific settings for defined course formats.
// They override any settings defined in the formats own config file.
//      $CFG->defaultblocks_site = 'site_main_menu,course_list:course_summary,calendar_month';
//      $CFG->defaultblocks_social =  'participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,course_list';
//      $CFG->defaultblocks_topics =  'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
//      $CFG->defaultblocks_weeks =  'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
// These blocks are used when no other default setting is found.

// $CFG->defaultblocks = 'participants,activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';

For example, to set the default block layout for topics format courses to People, Tags and Administration on the left, and Messages, Online users and Recent activity on the right, simply add the following line to your config.php file:

$CFG->defaultblocks_topics =  'participants,tags:messages,online_users,recent_activity';

Note how the colon is used to separate those blocks appearing on the left, from those appearing on the right and there is no space after each comma.

Resetting the block layout for existing courses

The block layout for existing courses may be reset by copying the following script into a text file, saving it as resetblocks.php, copying it into the Moodle root directory, then visiting http://yourmoodlesite.org/resetblocks.php.

Warning: This script may change the layout of your course pages and also remove blocks from those pages if they have not been specified in the config.php line. Check which of your courses has blocks which are not in the config.php line and be prepared to spend time adding blocks to your course pages again. Please note that a database backup is recommended before using the script.

M2.2 and later:

<?php
//moodle 2.2+
require_once('config.php');
require_once($CFG->libdir.'/blocklib.php');
$courses = get_courses();//can be feed categoryid to just effect one category
foreach($courses as $course) {
   $context = context_course::instance($course->id);
   blocks_delete_all_for_context($context->id);
   blocks_add_default_course_blocks($course);
} 
?>

M2.0 to M2.2:

<?php
//moodle 2.0 - 2.2
require_once('config.php');
require_once($CFG->libdir.'/blocklib.php');
$courses = get_courses();//can be feed categoryid to just effect one category
foreach($courses as $course) {
   $context = get_context_instance(CONTEXT_COURSE,$course->id);
   blocks_delete_all_for_context($context->id);
   blocks_add_default_course_blocks($course);
} 
?>