answer about autofiles for tags
[ikiwiki] / 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 <pre>
19 --- /usr/share/perl5/IkiWiki/Plugin/sidebar.pm  2010-02-11 22:53:17.000000000 -0500
20 +++ plugins/IkiWiki/Plugin/sidebar.pm   2010-02-27 09:54:12.524412391 -0500
21 @@ -19,12 +19,20 @@
22                         safe => 1,
23                         rebuild => 1,
24                 },
25 +               active_sidebars => {
26 +                       type => "string",
27 +                       example => qw(sidebar banner footer),
28 +                       description => "Which sidebars must be activated and processed.",
29 +                       safe => 1,
30 +                       rebuild => 1
31 +               },
32  }
33  
34 -sub sidebar_content ($) {
35 +sub sidebar_content ($$) {
36         my $page=shift;
37 +       my $sidebar=shift;
38         
39 -       my $sidebar_page=bestlink($page, "sidebar") || return;
40 +       my $sidebar_page=bestlink($page, $sidebar) || return;
41         my $sidebar_file=$pagesources{$sidebar_page} || return;
42         my $sidebar_type=pagetype($sidebar_file);
43         
44 @@ -49,11 +57,17 @@
45  
46         my $page=$params{page};
47         my $template=$params{template};
48 -       
49 -       if ($template->query(name => "sidebar")) {
50 -               my $content=sidebar_content($page);
51 -               if (defined $content && length $content) {
52 -                       $template->param(sidebar => $content);
53 +
54 +       my @sidebars;
55 +       if (defined $config{active_sidebars} && length $config{active_sidebars}) { @sidebars = @{$config{active_sidebars}}; }
56 +       else { @sidebars = qw(sidebar); }
57 +
58 +       foreach my $sidebar (@sidebars) {
59 +               if ($template->query(name => $sidebar)) {
60 +                       my $content=sidebar_content($page, $sidebar);
61 +                       if (defined $content && length $content) {
62 +                               $template->param($sidebar => $content);
63 +                       }
64                 }
65         }
66  }
67 </pre>
68
69 [[!tag wishlist]]