aboutsummaryrefslogtreecommitdiff
path: root/doc/todo/Give_access_to_more_TMPL__95__VAR_variables_in_templates_inserted_by_the_template_plugin.mdwn
blob: c71250b3a01816614b8126458b03d1c8cfa0fa87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
[[!tag wishlist patch]]

# Context

I may have missed a simple way to achieve what I need without
modifying ikiwiki, so here is the context.

I have a first-level directory (called `bricks`) containing a bunch of
wiki pages :

    /bricks
     |
     |- bla.mdwn
     |
     |- bli.mdwn
     |
     `- ...

I have two groups of tags called `direction` and `usage`, stored in
two sub-directories of `$tagbase` :

    /tag
     |
     |- direction
     |    |- d1.mdwn
     |    |- d2.mdwn
     |    |- ...
     |
     |- usage
     |    |- u1.mdwn
     |    |- u2.mdwn
     |    |- ...

Any page in `/brick` can be tagged with one or more tags from any of
these tags-groups.

I need to present different views for these wiki pages, so a `/view`
tree is dedicated to this mission :

    /view
     |
     |- dev
     |   |- d1.mdwn
     |   |- d2.mdwn
     |   |-...
     |
     |- howto
         |- u1.mdwn
         |- u2.mdwn
         |- ...

... where e.g. `/view/dev/d1` lists a subset (depending on other tags)
of the pages tagged d1.

My current plan is :

- thanks to the edittemplate plugin, `/view/dev/*` and `/view/howto/*` would contain respectively `\[[!template id=dev_direction]]` and `\[[!template id=howto_usage]]`
- `/templates/dev_direction.mdwn` and `/templates/howto_usage.mdwn` would use `\[[!map ...]]` directives to build their views

# My issue

Such map directives would look something like the following (more
complicated, actually, but let's focus on my current issue) :

	\[[!map pages="bricks/* and link(tag/usage/<TMPL_VAR BASENAME>)"]]

Where `BASENAME` value would be, e.g., `u1` or `d2`, depending on the
page inserting the template. But `BASENAME` does not exist. I found
that `<TMPL_VAR PAGE>` is replaced with the full path to the page, but
I did not found how to get the page's basename in a template included
with a `\[[!template id=...]]` directive.

Any idea ?

I guess it would be possible to provide the templates inserted by the
template plugin with more `TMPL_VAR` variables, but I don't know ikiwiki
codebase well, so I don't know how hard it would be.

I sure could write a ad-hoc plugin that would use the pagetemplate
hook to add a custom `<TMPL_LOOP>` selector I could use in my
templates, or another one that would use the filter hook to add the
needed `\[[!map ...]]` where it belongs to, but since ikiwiki's
preprocessor directives already *almost* do what I need, I'd like to
avoid the ad-hoc plugin solution.

(Adding a parameter such as `name=d1` in every `/view/dev/d*.mdwn` and
`/view/howto/u*.mdwn` page is not an option : I want to factorize the
most possible of these pages.

> The following patch adds a `basename` `TMPL_VAR` variable that can be
> used in the templates inserted by \[[!template plugin]] :

>        diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm
>        index a6e34fc..bb9dd8d 100644
>        --- a/IkiWiki/Plugin/template.pm
>        +++ b/IkiWiki/Plugin/template.pm
>        @@ -57,6 +57,8 @@ sub preprocess (@) {
>                       }
>               }
>        
>        +       $template->param("basename" => (split("/", $params{page}))[-1]);
>        +       
>               return IkiWiki::preprocess($params{page}, $params{destpage},
>                        IkiWiki::filter($params{page}, $params{destpage},
>                        $template->output));
>
> -- intrigeri

> Thanks for taking the trouble to develop a patch. [[done]] --[[Joey]]

>> Thanks :) -- intrigeri