]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/can__39__t_mix_template_vars_inside_directives.mdwn
new patch
[ikiwiki.git] / doc / bugs / can__39__t_mix_template_vars_inside_directives.mdwn
1 I often find myself wrapping the same boiler plate around [[ikiwiki/directives/img]] img directives, so I tried to encapsulate it using the following [[ikiwiki/directives/template]]:
2
3
4     <div class="image">
5     [\[!img <TMPL_VAR raw_href>
6     size="<TMPL_VAR raw_size>"
7     
8     <TMPL_IF alt>
9       alt="<TMPL_VAR raw_alt>"
10     <TMPL_ELSE>
11       <TMPL_IF caption>
12         alt="<TMPL_VAR raw_alt>"
13       <TMPL_ELSE>
14         alt="[pic]"
15       </TMPL_IF>
16     </TMPL_IF>
17     
18     ]]
19     <TMPL_IF caption>
20     <p><TMPL_VAR raw_caption></p>
21     </TMPL_IF>
22     </div>
23
24 The result, even with htmlscrubber disabled, is mangled, something like
25
26     <div class="image">
27     <span class="createlink"><a href="http://jmtd.net/cgi?
28         page=size&amp;from=log0.000000old_new_test&amp;do=create"
29         rel="nofollow">?</a>size</span>
30     
31     </div>
32
33 Any suggestions gladly received. -- [[Jon]]
34
35 > Well, you *should* be able to do things like this, and in my testing, I
36 > *can*. I used your exact example above (removing the backslash escape)
37 > and invoked it as:
38 >       \[[!template id=test href=himom.png size=100x]]
39
40 > And got just what you would expect.
41
42 > I don't know what went wrong for you, but I don't see a bug here. 
43 > My guess, at the moment, is that you didn't specify the required href
44 > and size parameters when using the template. If I leave those off,
45 > I of course reproduce what you reported, since the img directive gets
46 > called with no filename, and so assumes the size parameter is the image
47 > to display.. [[done]]? --[[Joey]] 
48
49 >> Hmm, eek. Just double-checked, and done a full rebuild. No dice! Version 3.20100831. Feel free to leave this marked done, It probably *is* PEBKAC. I shall look again in day time. -- [[Jon]]
50
51 >>> As always, if you'd like to mail me a larger test case that reproduces a
52 >>> problem for you, I can take a look at it. --[[Joey]]
53
54 >>>> <s>Thank you for the offer.  I might still take you up on it.  I've just proven that this
55 >>>> does work for a clean repo / bare bones test case. -- [[Jon]]</s> Figured it out. The
56 >>>> problem was I'd copied a page (old_new) which had two images embedded in it to test.
57 >>>> I'd stored the images under a subdir "old_new". The new page was called "old_new_test"
58 >>>> and the images thus could not be found by a pagespec "some-image.jpg". Adjusting the
59 >>>> href argument to the template (consequently the src argument to img) to
60 >>>> "old_new/some-image.jpg" fixed it all. [[done]], PEBKAC. Thank you for your time :)
61 >>>> -- [[Jon]]