]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/beef_up_sidebar_to_allow_for_multiple_sidebars.mdwn
recap of yamlfront issue opened on github
[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 -------------------
38
39 <pre>
40 --- /usr/share/perl5/IkiWiki/Plugin/sidebar.pm  2010-02-11 22:53:17.000000000 -0500
41 +++ plugins/IkiWiki/Plugin/sidebar.pm   2010-02-27 09:54:12.524412391 -0500
42 @@ -19,12 +19,20 @@
43                         safe => 1,
44                         rebuild => 1,
45                 },
46 +               active_sidebars => {
47 +                       type => "string",
48 +                       example => qw(sidebar banner footer),
49 +                       description => "Which sidebars must be activated and processed.",
50 +                       safe => 1,
51 +                       rebuild => 1
52 +               },
53  }
54  
55 -sub sidebar_content ($) {
56 +sub sidebar_content ($$) {
57         my $page=shift;
58 +       my $sidebar=shift;
59         
60 -       my $sidebar_page=bestlink($page, "sidebar") || return;
61 +       my $sidebar_page=bestlink($page, $sidebar) || return;
62         my $sidebar_file=$pagesources{$sidebar_page} || return;
63         my $sidebar_type=pagetype($sidebar_file);
64         
65 @@ -49,11 +57,17 @@
66  
67         my $page=$params{page};
68         my $template=$params{template};
69 -       
70 -       if ($template->query(name => "sidebar")) {
71 -               my $content=sidebar_content($page);
72 -               if (defined $content && length $content) {
73 -                       $template->param(sidebar => $content);
74 +
75 +       my @sidebars;
76 +       if (defined $config{active_sidebars} && length $config{active_sidebars}) { @sidebars = @{$config{active_sidebars}}; }
77 +       else { @sidebars = qw(sidebar); }
78 +
79 +       foreach my $sidebar (@sidebars) {
80 +               if ($template->query(name => $sidebar)) {
81 +                       my $content=sidebar_content($page, $sidebar);
82 +                       if (defined $content && length $content) {
83 +                               $template->param($sidebar => $content);
84 +                       }
85                 }
86         }
87  }
88 </pre>
89
90 ----------------------------------------
91 ## Further thoughts about this
92
93 (since the indentation level was getting rather high.)
94
95 What about using pagespecs in the config to map pages and sidebar pages together?  Something like this:
96
97 <pre>
98         sidebar_pagespec => {
99             "foo/*" => 'sidebars/foo_sidebar',
100             "bar/* and !bar/*/*' => 'bar/bar_top_sidebar',
101             "* and !foo/* and !bar/*" => 'sidebars/general_sidebar',
102         },
103 </pre>
104
105 One could do something similar for *pageheader*, *pagefooter* and *rightbar* if desired.
106
107 Another thing which I find compelling - but probably because I am using [[plugins/contrib/field]] - is to be able to treat the included page as if it were *part* of the page it was included into, rather than as an included page.  I mean things like \[[!if ...]] would test against the page name of the page it's included into rather than the name of the sidebar/header/footer page.  It's even more powerful if one combines this with field/getfield/ftemplate/report, since one could make "generic" headers and footers that could apply to a whole set of pages.
108
109 Header example:
110 <pre>
111 #{{$title}}
112 \[[!ftemplate id="nice_data_table"]]
113 </pre>
114
115 Footer example:
116 <pre>
117 ------------
118 \[[!report template="footer_trail" trail="trailpage" here_only=1]]
119 </pre>
120
121 (Yes, I am already doing something like this on my own site.  It's like the PmWiki concept of GroupHeader/GroupFooter)
122
123 -- [[KathrynAndersen]]
124
125 [[!tag wishlist]]
126
127 > I am stumbling upon this discussion, and I noticed that I implemented part of [[KathrynAndersen]] idea in the [[plugins/contrib/sidebar2]] [[plugin|plugins]]. Using this plugin, you can have several sidebars, which are included only in pages matching some pagespec.
128
129 > [[Louis|spalax]]