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