Template:Plain image with caption: Difference between revisions

From KB42
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->


Since MediaWiki does not provide a way to add visible captions to images integrated seamlessly in a page (i.e, without borders), this template aims to provide that functionality.
{| class="wikitable"
|+ Caption text
|-
! Header text
|-
| [[File:{{{image}}}|center|]]
|-
| {{{caption}}}
|}


=== Usage ===
 
This template can be either with named parameters, as in
{|
:<code><nowiki>{{plain image with caption|image=Example.svg|caption=Example text|width=250|align=right}}</nowiki></code>
| [[File:{{{1|{{{image}}}}}}|center|{{{3|{{{width|250}}}}}}px|{{{2|{{{caption}}}}}}]]
...or in its shorthand form:
:<code><nowiki>{{plain image with caption|Example.svg|Example text|250|right}}</nowiki></code>
* The only compulsory parameters are <code>image</code> and <code>caption</code>. The width defaults to 250px, and the alignment defaults to right
* When using the shorthand version, keep in mind that the order of parameters is important
* Please notice that the width does not include the unit "px" (see the code below)
===Technical===
The template wraps the image in an '''HTML table wrapper''' ''bounding the wrapper margins relative to the image width''. The table positions the construct right or left and isolates it from other page text intrusion with fixed padding.
====Actual internal coding====
The equivalance between placeholder and named parameters is shown here below:
<pre>
{| style="float:{{{4|{{{align|right}}}}}}; width:{{{3|{{{width|250}}}}}}px;
margin:1em; background:transparent;"
| [[Image:{{{1|{{{image<noinclude>|Example.svg</noinclude>}}}}}}
| right|{{{3|{{{width|250}}}}}}px|{{{2|{{{caption<noinclude>|Caption goes here.</noinclude>}}}}}}]]
|-
|-
|<span style="font-size:85%;">{{{2|{{{caption<noinclude>|Caption goes here.</noinclude>}}}}}}</span>
|<span style="font-size:85%;">{{{2|{{{caption}}}}}}</span>
|}</pre>
|}
 
So the placeholder parameters map as named parameters to operational HTML in order:
# <code>image: &nbsp; <nowiki>{{{image}}} or {{{1|}}}</nowiki></code>
# <code>caption:&nbsp;<nowiki>{{{caption}}} or {{{2|}}}</nowiki></code>
# <code>width:  &nbsp;<nowiki>{{{width}}} or {{{3|}}}</nowiki></code>&mdash; '''defaults to 250 and  ''adds the 'px;'''''' ''suffix'', so leave it off!
# <code>float: &nbsp; <nowiki>{{{align}}} or {{{4|}}}</nowiki></code>
<includeonly>
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
[[Category:Graphic templates|{{PAGENAME}}]]
[[category:Typing-aid templates|{{PAGENAME}}]]
</includeonly>

Latest revision as of 02:05, 2 April 2023

Caption text
Header text
[[File:{{{image}}}|center|]]
{{{caption}}}


[[File:{{{image}}}|center|250px|{{{caption}}}]]
{{{caption}}}