By Alderman
Description
Would you like to have a ready-made, easy to use template for including placeable thumbnail images with a caption (similar to that seen on Wikipedia)? It is surprisingly easy to do, and can be used to great benefit on numerous pages.
Creating the Template
1. Create a new page with an appropriate title, e.g.: template:thumb. This will contain the template you are about to create.
2. Add the following code to the wiki text editor:
Code block 1:
[[div style="float:{$placement}; margin:0em 2.5em 0.1em 1em; width:{$width}; border:1em"]]
||= [[image {$image} width="{$width}" style="border:1em" alt="{$caption}" link="{$link}"]]||
|| ^^{$caption}^^ ||
[[/div]]
3. Save the page. Done! You now have a new template you can use on any page where you need a captioned image.
Using the Template
1. Go to the page where you would like to insert a captioned image.
2. Click on "edit" to open the editor window.
3. Add the following code above the text next to which the image should appear:
Code block 2:
[[include template:thumb]]
4. Now all you need to do is specify the parameters made available to you via the template you just created. For this template, these are:
- placement: right or left
- width: any numerical value followed by px (="pixels"), e.g.: 300px
- image: the URL to your image
- caption: the text you would like to have appear beneath the image. Note: IE users will also see this text when they roll over the image with their cursor.
- link: the URL or wiki-link you would like to have the image link to (e.g. if you have the image on its own page).
To specify these parameters, you need to:
5. Immediately after the template name (in this case: "thumb") but before the double bracket (]), hit enter twice, creating an empty line.
6. Start the new line with a vertical bar (|).
7. Add the name of the variable you want to specify (e.g. either "placement", "width", "image", "caption" or "link").
8. After the variable name, add the "=" sign followed by the specific value, URL, text, etc.
9. For each variable, add a new line headed with a vertical bar (|).
10. Be sure to close the code with a double bracket (])
11. Save your work. Done!
In action
For the following example, the parameters have been defined as:
|placement=right
|width=200px
|image=https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Otira_River_in_Arthur%27s_Pass_National_Park%2C_New_Zealand.jpg/1920px-Otira_River_in_Arthur%27s_Pass_National_Park%2C_New_Zealand.jpg
|caption=Otira River in Arthur's Pass National Park, New Zealand.
|link=image:bracteate-funen-jpg
Here is a screen-shot of the template in action with the values specified above:
Additional notes
- Remember: You can re-use this template on any page as many times as you like. The single template will do all the work.
- The 'link' parameter in the template will not work with the module Backlinks. Thus, it is not possible to use the module Backlinks on the image's page to create a list of the pages on which it appears.
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by Alderman
Rate this solution
If you think this solution is useful — rate it up!
[[include template:thumb
|placement=right
|width=200px
|image=http://img73.imageshack.us/img73/9642/639pxbracteatefromfunenwy1.jpg
|caption=Migration Age bracteate from Funen island
|link=image:bracteate-funen-jpg
]]
I'd like to format the captions for the images I'm going to use (multiple line, formatted captions). Will this solution provide for multiple line captions?
Thanks.
Hey David,
You posted the same thing on another thread and I spent some time writing an in-depth response. Please read my comment there for an answer :)
http://community.wikidot.com/forum/t-177982/captions-for-graphics#post-797139
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
I love this, very simple and easy to use. It was also exactly the thing I was looking for. Thanks!
Meanwhile, Phil's wife was learning to use Wikidot and look what she found out:
http://community.wikidot.com/howto:put-pictures-with-footnotes-in-the-text-using-divs
If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney
Sitting at his desk in his living room, Phil, cigarette in one hand raises his left buttock as he passes a silent one, writes:-
My wife Brunhilda reported a problem with this here.
http://community.wikidot.com/forum/t-73350/problems-with-different-types-of-browsers#post-218932
With a little messing about i discovered the problem was cause by the code below
Removal of the style="border:1em" seems to cure the problem.
But I found that to get it working for me I had to substitute the term "include" for "insert" in Code Block 2. Bye the way, what a beautiful coin! … Tom
Indeed, Tom, you were right. My mistake there. Though, it did help me detect a different bug: the [[code]] block does not turn off the [[include]] tag…
Also, the margin values have been adjusted after another user kindly notified me that the 'right' placement was not optimal. The present version should now look the same in either 'left' or 'right' placement.
Thanks again!
—Alderman