شابلون:پیکسل
بو {{px}} شابلوندو.
بو متا-شابلون باشقا شابلونلارا،مثلا infoboxes، کوک ایلیر تصویرین اولچو پارامتری هر ایکی فورمتی "40" یادا "40px" قبول ایلسین.
ایستیفاده
[دَییشدیر]Here is what this template does. Code to the left, actual rendering to the right:
{{px|40}}
= 40px{{px|40px}}
= 40px
And with an optional second or even third parameter to be used as a default value if the first or second parameter is empty or undefined:
{{px||50}}
= 50px{{px||50px}}
= 50px
{{px|||60}}
= 60px{{px|||60px}}
= 60px
And here is how it can be used inside another template:
[[Image:{{{image}}} | {{px|{{{size|}}}}} | {{{caption|}}} ]]
[[Image:{{{image}}} | {{px|{{{size|}}}|250}} | {{{caption|}}} ]]
[[Image:{{{image}}} | {{px| {{{size|}}} | {{{width|}}} | 250 }} | {{{caption|}}} ]]
Default values
[دَییشدیر]It used to be a bit tricky to handle empty but defined image size values in a template, since the MediaWiki pipetrick doesn't return the default value for empty parameters. That is, {{{width|250px}}}
does not return "250px" if the template was called like this: {{Tl|width=}}
The usual workaround was to do like this:
{{#if:{{{width|}}}|{{{width}}}|250px}}
When at the same time handling the "pxpx" bug this became even more messy code:
[[Image:{{{image}}} | {{#if:{{{width|}}}|{{px|{{{width}}}}}|250px}} ]]
To simplify the coding, {{px}} allows for an optional default value to be defined allowing for the following:
[[Image:{{{image}}} | {{px|{{{width|}}}|250}} ]]
Note! The parameters to {{px}} must use the pipe "|", like this: {{{width|}}}
. Or else {{px}} will be fed and return the string "{{{width}}}
" if width was not defined.
Background
[دَییشدیر]Old usage was to always pad on "px" since MediaWiki used to tolerate "40pxpx":
[[Image:{{{image}}} | {{{size}}}px | {{{caption|}}} ]]
But since 25 March ۲۰۰۸ (میلادی) that does not work anymore. That is, image sizes on Wikipedia now needs to be given in the form "40px", not "40" or "40pxpx". This template helps doing that. Note that the bug has since been fixed, although you can continue using this template.
See also
[دَییشدیر]- Wikipedia:ClickFix – About the "pxpx" bug.
- {{ifempty}} – Helps detect empty parameters and fall back to default values. For instance for handling multiple image name parameters.
Test examples
[دَییشدیر]{{px|40}}
= 40px{{px|40px}}
= 40px{{px|40pxpx}}
= 40pxpx{{px|junk}}
= junk{{px}}
={{px}}
={{px}}
={{px}}
={{px|40|50}}
= 40px{{px||50}}
= 50px{{px||50px}}
= 50px{{px||50|60}}
= 50px{{px|||60}}
= 60px{{px|||60px}}
= 60px
[[Image:Example.png | 50 | thumb ]]
=
[[Image:Example.png | 50pxpx | thumb ]]
=
- Currently fails. But the devs have stated that they are adding back parsing of "pxpx" in the next update to Wikipedia. So if you see a small image to the right then Wikipedia again accepts "pxpx".
[[Image:Example.png | 50px | thumb ]]
=
[[Image:Example.png | {{px|50}} | thumb ]]
=
[[Image:Example.png | {{px|50px}} | thumb ]]
=
[[Image:Example.png | {{px|junk}} | thumb ]]
=
[[Image:Example.png | {{px|}} | thumb ]]
=
[[Image:Example.png | {{px}} | thumb ]]
=
[[Image:Example.png | {{px||50}} | thumb ]]
=
- Giving the default width if the 1st parameter is empty
[[Image:Example.png | {{px|{{{width|}}}|50}} | thumb ]]
=
[[Image:Example.png | {{px|{{{width}}}|50}} | thumb ]]
=
- Fails to use the default value of 50. Note the missing "|" in {{{width}}}.
[[Image:Example.png | {{px| {{{width|}}} | {{{size|}}} | 50 }} | thumb ]]
=