hnb: Fixed broken use of mkstemp that had caused dangling temp files, and prevented...
[ikiwiki.git] / doc / todo / beef_up_sidebar_to_allow_for_multiple_sidebars.mdwn
1 Maybe sidebar could be beefed up to take the name of a sidebar, such that I could use multiple sidebars in the same wiki. For instance, the default name would be 'sidebar', meaning the plugin looks for `sidebar.pm` and fills in the `sidebar` slot, but I might also want a footer in `footer.pm`, filling the template's `footer` slot.
2
3 One good way (if possible) would be to provide a directive like `\[[!sidebar
4 id=sidebar]]` which would cause the file, in which it occurred to fill the
5 slot `SIDEBAR` in the template: basically, a page `foo.mdwn` says
6 `\[[!fillslot slot=myslot]]` and then its contents should go into `<TMPL_VAR
7 SLOT_MYSLOT>` for all pages. Ideally, this can then be overridden, so if
8 `/bar/foo.mdwn` also references `myslot` then pages under `/bar` should get
9 those contents instead.
10
11
12 --[[madduck]]
13
14 > In mine I just copied sidebar out and made some extra "sidebars", but they go elsewhere. Ugly hack, but it works. --[[simonraven]]
15
16 >> Here a simple [[patch]] for multiple sidebars. Not too fancy but better than having multiple copies of the sidebar plugin. --[[jeanprivat]]
17
18 >>> I made a [[git]] branch for it [[!template id=gitbranch branch="privat/multiple_sidebars" author="[[jeanprivat]]"]] --[[jeanprivat]]
19
20 >>>> Ping for [[Joey]]. Do you have any comment? I could improve it if there is things you do not like. I prefer to have such a feature integrated upstream. --[[JeanPrivat]]
21
22 >>>>> The code is fine.
23 >>>>>
24 >>>>> I did think about having it examine
25 >>>>> the `page.tmpl` for parameters with names like `FOO_SIDEBAR`
26 >>>>> and automatically enable page `foo` as a sidebar in that case,
27 >>>>> instead of using the setup file to enable. But I'm not sure about
28 >>>>> that idea..
29 >>>>> 
30 >>>>> The full compliment of sidebars would be a header, a footer,
31 >>>>> a left, and a right sidebar. It would make sense to go ahead
32 >>>>> and add the parameters to `page.tmpl` so enabling each just works,
33 >>>>> and add whatever basic CSS makes sense. Although I don't know
34 >>>>> if I want to try to get a 3 column CSS going, so perhaps leave the
35 >>>>> left sidebar out of that.
36
37 <pre>
38 --- /usr/share/perl5/IkiWiki/Plugin/sidebar.pm  2010-02-11 22:53:17.000000000 -0500
39 +++ plugins/IkiWiki/Plugin/sidebar.pm   2010-02-27 09:54:12.524412391 -0500
40 @@ -19,12 +19,20 @@
41                         safe => 1,
42                         rebuild => 1,
43                 },
44 +               active_sidebars => {
45 +                       type => "string",
46 +                       example => qw(sidebar banner footer),
47 +                       description => "Which sidebars must be activated and processed.",
48 +                       safe => 1,
49 +                       rebuild => 1
50 +               },
51  }
52  
53 -sub sidebar_content ($) {
54 +sub sidebar_content ($$) {
55         my $page=shift;
56 +       my $sidebar=shift;
57         
58 -       my $sidebar_page=bestlink($page, "sidebar") || return;
59 +       my $sidebar_page=bestlink($page, $sidebar) || return;
60         my $sidebar_file=$pagesources{$sidebar_page} || return;
61         my $sidebar_type=pagetype($sidebar_file);
62         
63 @@ -49,11 +57,17 @@
64  
65         my $page=$params{page};
66         my $template=$params{template};
67 -       
68 -       if ($template->query(name => "sidebar")) {
69 -               my $content=sidebar_content($page);
70 -               if (defined $content && length $content) {
71 -                       $template->param(sidebar => $content);
72 +
73 +       my @sidebars;
74 +       if (defined $config{active_sidebars} && length $config{active_sidebars}) { @sidebars = @{$config{active_sidebars}}; }
75 +       else { @sidebars = qw(sidebar); }
76 +
77 +       foreach my $sidebar (@sidebars) {
78 +               if ($template->query(name => $sidebar)) {
79 +                       my $content=sidebar_content($page, $sidebar);
80 +                       if (defined $content && length $content) {
81 +                               $template->param($sidebar => $content);
82 +                       }
83                 }
84         }
85  }
86 </pre>
87
88 [[!tag wishlist]]