(no commit message)
[ikiwiki] / doc / forum / link_to_an_image_inside_the_wiki_without_inlining_it.mdwn
1 how can I create a link to an image which is part of the wiki, without having it inserted in my page?
2
3 I tought this:
4
5     \[[look at this|img/lolcat.png]] 
6
7 would work, but it doesn't.
8
9 Any hints? --[[jerojasro]]
10
11 > Well, currently the syntax above will display the image
12 > inline with the specified link text used as an alt attribute. Although
13 > that does not seem to be documented anywhere.
14
15 > A few places that use that (found with `git grep '\[\[' | egrep 'png|gif|jpeg|jpg' |grep \|`):
16
17 > * [[logo]] uses it to provide useful alt texts for the logos. (This
18 >   could easily be changed to use [[ikiwiki/directive/img]] though.)
19 > * The `change.tmpl` template uses it to display 
20 >   the [[diff|wikiicons/diff.png]] with a very useful "diff" alt text.
21 >   Using [[ikiwiki/directive/img]] here would mean that the
22 >   [[plugins/recentchanges]] plugin would depend upon the img
23 >   plugin.
24
25 > I do like your suggestion, it makes more sense than the current behavior.
26 > I'm not sure the transition pain to get from here to there is worth it,
27 > though.
28
29 > More broadly, if I were writing ikiwiki now, I might choose to leave out the
30 > auto-inlining of images altogether. In practice, it has added a certian level
31 > of complexity to ikiwiki, with numerous plugins needing to specify
32 > `noimageinline` to avoid accidentially inlining an image. And there has not
33 > been a lot of payoff from having the auto-inlining feature implicitly
34 > available most places. And the img directive allows much needed control over
35 > display, so it would be better for users to not have to worry about its
36 > lesser cousin. But the transition from here to *there* would be another order
37 > of pain.
38
39 > Anyway, the cheap and simple answer to your question is to use html
40 > or markdown instead of a [[ikiwiki/wikilink]]. Ie, 
41 > `[look at this](img/lolcat.jpg)`. --[[Joey]]
42
43 > > thanks a lot, that's a quite straightforward solution. I actually wrote a
44 > > broken plugin to do that, and now I can ditch it --[[jerojasro]]
45
46 >>> The plugin approach is not a bad idea if you want either the ability
47 >>> to:
48 >>>
49 >>> * Have things that are wikilink-aware (like [[plugins/brokenlinks]]
50 >>>   treat your link to the image as a wikilink. 
51 >>> * Use standard wikilink path stuff (and not have to worry about 
52 >>>   a relative html link breaking if the page it's on is inlined, for
53 >>>   example).
54 >>>
55 >>> I can help you bang that plugin into shape if need be. --[[Joey]] 
56
57 >>>> both my plugin and your suggestion yield broken html links when inlining the page (although probably that's what is expected from your suggestion (`[]()`))
58 >>>>
59 >>>> I thought using the `bestlink` function would take care of that, but alas, it doesn't.
60 >>>> Get the "plugin" [here](http://devnull.li/~jerojasro/files/linktoimgonly.pm), see the broken 
61 >>>> links generated [here](http://devnull.li/~jerojasro/blog/posts/job_offers/) and the source 
62 >>>> file for that page [here](http://git.devnull.li/cgi-bin/gitweb.cgi?p=blog-jerojasro.git;a=blob;f=posts/job_offers.mdwn;hb=HEAD) --[[jerojasro]]
63
64 >>>>> Use this --[[Joey]] 
65
66         return htmllink($params{page}, $params{destpage}, $params{"img"},
67             linktext => $params{text},
68             noimageinline => 1);
69