root/releases/0.9rc1/mod/sidebar/README

Revision 1372, 2.3 kB (checked in by rho, 1 year ago)

updated plugin documentation

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

Line 
1 New sidebar plugin
2 ==================
3
4 This plugins allow to manage in a better way the sidebar.
5 And adds per-block user configuration (show/hide).
6
7 Plugin functions
8 ================
9
10 /**
11  * Adds new block to sidebar stack
12  *
13  * @param integer $weigth the weight/position of the block
14  * @param string $id unique block identificator
15  * @param bool $userdetails allow users to show/hide (true or false)
16  * @param string $label label to show on account settings
17  * @param string $class optional css class
18  */
19 function sidebar_add($weight, $id, $body, $userdetails=false, $label=null, $class=null)
20
21
22 /**
23  * Removes a block or blocks from sidebar
24  *
25  * @param mixed $id block identificator to remove, string or array of id's
26  * @param bool $overrideall if all blocks will be removed except provided $id
27  */
28 function sidebar_remove($id, $overrideall=false)
29
30 How to use
31 ==========
32
33 - On legacy sidebar code
34
35 Usually sidebar elements are attached to $function['display:sidebar'],
36 for example blog sidebar menu:
37
38 [code]
39
40 $function['display:sidebar'][] = $CFG->dirroot . 'mod/blog/lib/weblogs_user_info_menu.php';
41
42 [/code]
43
44 You must define new function on _init, for example:
45
46 [code]
47
48 $function['sidebar:blog'][] = $CFG->dirroot . 'mod/blog/lib/weblogs_user_info_menu.php';
49
50 [/code]
51
52 Then in _pagesetup, add the sidebar element:
53
54 [code]
55
56 $blog_menu = run('sidebar:blog'); // get the output of legacy sidebar
57 $blog_menu = sidebar_legacy_wrap($blog_menu); // remove legacy unneeded html code <li></li>
58
59 sidebar_add(20, 'sidebar-blog', $blog_menu, true, "Your blog"); // add the block to sidebar with weight 20
60
61 [/code]
62
63
64 - On new plugins
65
66 Just build your block body as usual:
67
68 [code]
69
70 $body = templates_draw(array(
71         'context' => 'sidebarholder',
72         'title' => 'My new block',
73         'body' => 'Hello world',
74         ));
75
76 sidebar_add(50, 'sidebar-myblock', $body, true, "new block");
77
78 Or use a function to render sidebar block
79
80 // my function to render block
81 function myplugin_sidebar() {
82         //...
83         return $body;
84 }
85 // use function name as identificator
86 sidebar_add(50, 'myplugin_sidebar', null, true, "new block");
87
88 [/code]
89
90 That's all.
91
92 And yes, you can use negative values on weight ;-)
93
94 - Removing sidebaa blocks
95
96 As simple as: sidebar_remove('sidebar-myblock');
97
98 --
99 Rolando Espinoza La fuente <rho@prosoftpeople.com>
100 Pro Soft Resources Inc.
Note: See TracBrowser for help on using the browser.