]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn
(no commit message)
[ikiwiki.git] / doc / todo / Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn
1 [[!tag wishlist patch]]
2
3 # Context
4
5 I may have missed a simple way to achieve what I need without
6 modifying ikiwiki, so here is the context.
7
8 I have a first-level directory (called `bricks`) containing a bunch of
9 wiki pages :
10
11     /bricks
12      |
13      |- bla.mdwn
14      |
15      |- bli.mdwn
16      |
17      `- ...
18
19 I have two groups of tags called `direction` and `usage`, stored in
20 two sub-directories of `$tagbase` :
21
22     /tag
23      |
24      |- direction
25      |    |- d1.mdwn
26      |    |- d2.mdwn
27      |    |- ...
28      |
29      |- usage
30      |    |- u1.mdwn
31      |    |- u2.mdwn
32      |    |- ...
33
34 Any page in `/brick` can be tagged with one or more tags from any of
35 these tags-groups.
36
37 I need to present different views for these wiki pages, so a `/view`
38 tree is dedicated to this mission :
39
40     /view
41      |
42      |- dev
43      |   |- d1.mdwn
44      |   |- d2.mdwn
45      |   |-...
46      |
47      |- howto
48          |- u1.mdwn
49          |- u2.mdwn
50          |- ...
51
52 ... where e.g. `/view/dev/d1` lists a subset (depending on other tags)
53 of the pages tagged d1.
54
55 My current plan is :
56
57 - thanks to the edittemplate plugin, `/view/dev/*` and `/view/howto/*` would contain respectively `\[[!template id=dev_direction]]` and `\[[!template id=howto_usage]]`
58 - `/templates/dev_direction.mdwn` and `/templates/howto_usage.mdwn` would use `\[[!map ...]]` directives to build their views
59
60 # My issue
61
62 Such map directives would look something like the following (more
63 complicated, actually, but let's focus on my current issue) :
64
65         \[[!map pages="bricks/* and link(tag/usage/<TMPL_VAR BASENAME>)"]]
66
67 Where `BASENAME` value would be, e.g., `u1` or `d2`, depending on the
68 page inserting the template. But `BASENAME` does not exist. I found
69 that `<TMPL_VAR PAGE>` is replaced with the full path to the page, but
70 I did not found how to get the page's basename in a template included
71 with a `\[[!template id=...]]` directive.
72
73 Any idea ?
74
75 I guess it would be possible to provide the templates inserted by the
76 template plugin with more `TMPL_VAR` variables, but I don't know ikiwiki
77 codebase well, so I don't know how hard it would be.
78
79 I sure could write a ad-hoc plugin that would use the pagetemplate
80 hook to add a custom `<TMPL_LOOP>` selector I could use in my
81 templates, or another one that would use the filter hook to add the
82 needed `\[[!map ...]]` where it belongs to, but since ikiwiki's
83 preprocessor directives already *almost* do what I need, I'd like to
84 avoid the ad-hoc plugin solution.
85
86 (Adding a parameter such as `name=d1` in every `/view/dev/d*.mdwn` and
87 `/view/howto/u*.mdwn` page is not an option : I want to factorize the
88 most possible of these pages.
89
90 > The following patch adds a `basename` `TMPL_VAR` variable that can be
91 > used in the templates inserted by \[[!template plugin]] :
92
93 >        diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm
94 >        index a6e34fc..bb9dd8d 100644
95 >        --- a/IkiWiki/Plugin/template.pm
96 >        +++ b/IkiWiki/Plugin/template.pm
97 >        @@ -57,6 +57,8 @@ sub preprocess (@) {
98 >                       }
99 >               }
100 >        
101 >        +       $template->param("basename" => (split("/", $params{page}))[-1]);
102 >        +       
103 >               return IkiWiki::preprocess($params{page}, $params{destpage},
104 >                        IkiWiki::filter($params{page}, $params{destpage},
105 >                        $template->output));
106 >
107 > -- intrigeri
108
109 > Thanks for taking the trouble to develop a patch. [[done]] --[[Joey]]
110
111 >> Thanks :) -- intrigeri