Help talk:Extension:ParserFunctions/2012
This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archives
|
---|
Using #if to generate conditional table rows
I'm running into a problem using #if to generate multiple conditional rows in succession. The issue, I believe, stems from line breaks, or lack thereof. If you use line breaks to separate the #if statements, new rows created with |- will appear correctly, but when the condition is false, the line breaks are still generated as white space (html P or BR), causing the last cell to have an extra line. On the other hand, if you keep the #if statements on the same line, there appears to be no way to generate a line break at the start of the output because the parser strips it. So |- will not appear on a new line, and therefore fails to generate a new row (it instead just gets rendered as text). 76.253.0.17 03:12, 26 September 2011 (UTC)
- Same probleme here. Found any solution? Drhirn 13:03, 8 November 2011 (UTC)
- Why not just just use html tags? --Subfader 18:14, 8 November 2011 (UTC)
- Try using the same-line method and placing a invisible character (like
&8201;
or​
) at the beginning of the output, before the line break. The innocuous character will then be added to the end of previous cell, and the line break will not be ignored. Note:&8201;
is a very thin space and​
is a zero-width space. Gustronico 17:47, 17 November 2011 (UTC)- Using zero-width spaces inside the parser function is a nice hack, but it adds another problem. If predecing cell ends with a
<br>
tag, the zero-width space character causes the preceding cell to end as<br>​
instead, which also renders an unwanted empty line to the end of the table cell. - 91.157.56.116 15:36, 7 August 2013 (UTC)
- Using zero-width spaces inside the parser function is a nice hack, but it adds another problem. If predecing cell ends with a
- Try using the same-line method and placing a invisible character (like
- Why not just just use html tags? --Subfader 18:14, 8 November 2011 (UTC)
Checking if an external link exists
Is there a way to use #if, #ifeq or other ParserFunctions to check if an external URL exists or not (i.e., whether a web page is a dead link)? Smuconlaw 17:59, 15 January 2012 (UTC)
- No. The wiki parser knows the status of its own pages only by checking its internal database (it does not actually try to load the webpage). It has no way of knowing whether pages exist if they are on unrelated domains. On some wikis, experienced editors occasionally run bots to check the status of external links and edit wikitext containing broken links, but that is unrelated to parser functions. — Richardguk 22:50, 15 January 2012 (UTC)
- Ah, OK. Thanks. A template ({{Singapore Statute}}) at the English Wikipedia relies on an external website, but the managers of that website have launched an updated website which is quite different. I was wondering if the template could be tweaked to check if the old website is still accessible, and, if not, to access the new website instead. Looks like I should wait till the old website has been completely turned off, then rejig the template to link to the new website. — Cheers, SMUconlaw 09:56, 16 January 2012 (UTC)
ifeq match this or that
Is there a way to compare multiple values with a string?
{{#ifeq: this | value1 OR value2 OR value3 | yes | no }}
I know I could nest the #ifeq-tags but that results in ugly tag soups.
I could also use #switch but then i have to repeat the output for each. --Subfader (talk) 18:23, 26 March 2012 (UTC)
- #switch will accept multiple possibilities for each output, so the following would output "yes" for this equal to any of "value1", "value2" or "value3", or output "no" otherwise:
{{#switch: this | value1 | value2 | value3 = yes | #default = no }}
- See Help:Extension:ParserFunctions#Grouping results for a different example.
- — Richardguk (talk) 18:41, 26 March 2012 (UTC)
- Oh, great :) --Subfader (talk) 06:49, 27 March 2012 (UTC)
No integer division ???
Why is there no integer division for #expr ? There is a modulo operator but no integer division. This is not logical to have one feature and not the other.
We have to subtract 0.5 and then round to 0 digits. Instead div should be the integer division and / should be the decimal division.
--DavidL (talk) 13:32, 15 April 2012 (UTC)
Template:Ifnumber
- To simplify a complex template, I made a Template:Ifnumber witch detect if an expression is numeric, but else do not generate any error.
- example : {{Ifnumber| 231 | true text | false text }}
- Is it a short equivalent, or this template could become a parse function ? Rical (talk) 15:29, 15 April 2012 (UTC)
- I don't think we need to add another ParserFunction for a feature that can be so easily achieved with a short amount of code using existing functions. Happy‑melon 14:11, 17 April 2012 (UTC)
Creating a new line...
I am wondering if any of you guys can help me. I am attempting to use ParserFunctions to create a unit converter for my wiki. The issue is that the "#expr" code is creating a new line after every use. My code is below. Any help would be SOOOOO appreciated! Thanks!!! --Zackmann08 (talk) 22:22, 1 May 2012 (UTC)
The template:
<includeonly>"{{#expr:({{{1}}}* 2.2046)round2}} lbs ({{{1}}} kg)"</includeonly>
The use of the template:
* '''Weight''': {{convert/kg|1}} * '''Weight''': {{convert/kg|2}}
What it produces:
- Weight: "2.2 lbs (1 kg)"
- Weight: "4.41 lbs (2 kg)"
What I WANT it to produce:
- Weight: "2.2 lbs (1 kg)"
- Weight: "4.41 lbs (2 kg)"
- Hello, you have to make sure that the transcluded part is inline (when you need it to be). This means no Enters in the part that will be transcluded with the template. This can go wrong when you transclude a category with a template. If there is a Enter after the category it will get transcluded. Also, when you save the page starting with a Enter it will not show when you edit it again but it is still there. If you want more layout control we always exactly "tell" the wiki engine what needs to be transcluded. See example that will work below (on MW 1.17.2):
[[category:test]]<noinclude> == Any Template documentation == * Bla bla 1 * Bla bla 2 * Bla bla 3</noinclude><includeonly>"{{#expr:({{{1}}}* 2.2046)round2}} lbs ({{{1}}} kg)"</includeonly>
When you have a Enter between the category and the <noinclude> it will mess up the result. --Jongfeli (talk) 11:46, 2 May 2012 (UTC)
- THANK YOU SOOOOO MUCH!!!!! That really helped!!! --Zackmann08 (talk) 22:20, 2 May 2012 (UTC)
lenght of a string
Hi, I just want to share parser function to find lenght of a given string.You can find the template here, but it is in Turkish. It is up to 10 characters but you can increase. the size.
- code =
{{ #ifeq: {{padleft:|1|{{{1|}}}}} | {{{1|}}} | 1 | {{ #ifeq: {{padleft:|2|{{{1|}}}}} | {{{1|}}} | 2 | {{ #ifeq: {{padleft:|3|{{{1|}}}}} | {{{1|}}} | 3 | {{ #ifeq: {{padleft:|4|{{{1|}}}}} | {{{1|}}} | 4 | {{ #ifeq: {{padleft:|5|{{{1|}}}}} | {{{1|}}} | 5 | {{ #ifeq: {{padleft:|6|{{{1|}}}}} | {{{1|}}} | 6 | {{ #ifeq: {{padleft:|7|{{{1|}}}}} | {{{1|}}} | 7 | {{ #ifeq: {{padleft:|8|{{{1|}}}}} | {{{1|}}} | 8 | {{ #ifeq: {{padleft:|9|{{{1|}}}}} | {{{1|}}} | 9 | {{ #ifeq: {{padleft:|10|{{{1|}}}}} | {{{1|}}} | 10 | 11}}}}}}}}}}}}}}}}}}}} Saltinbas (talk) 15:15, 14 May 2012 (UTC)
#switch/#ifeq with apostrophes
For example, if you're matching a pagename that contains an apostrophe to the plain text version
{{#ifeq: {{PAGENAME}}|The Page's Name|y|n}}
the result always comes out to be 'n', oddly.
Anyone know a loop around this? --108.224.95.15 05:50, 25 July 2012 (UTC)
- Nevermind, replacing the apostrophe with ' ; works. --108.224.95.15 05:54, 25 July 2012 (UTC)
replacing #ifexist with #dpl
The behaviour of #ifexist
can be reproduced with DPL using the following syntax:
{{#dpl:title= page title |oneresultheader= value if exists |noresultsheader= value if doesn't exist }}
which is equivalent to:
{{#ifexist: page title | value if exists | value if doesn't exist }}
DPL has the advantage that it does not create a link between the target page (page title) and the page containing the query. Using #ifexist
would cause your page to be listed in Special:WhatLinksHere/page_title.
—Capmo (talk) 06:42, 18 August 2012 (UTC)
- #ifexist is faster. Avoid calling DPL wherever you can. --Subfader (talk) 13:23, 19 August 2012 (UTC)
- DPL makes direct queries to the database, what can be faster than this? And there must be a reason for #ifexist to be labeled as an "expensive parser function". The wiki I administer uses DPL extensively for all sorts of things, and we don't feel any perceivable degradation in server performance. Capmo (talk) 21:53, 21 August 2012 (UTC)
- Initializing DPL on page load takes longer than ParserFunctions.
"#ifexist to be labeled as an "expensive parser function"" that's because the DB load gets expensive on calling it X times, but the same counts for calling DPL X times on a page... --Subfader (talk) 11:50, 22 August 2012 (UTC)
- Initializing DPL on page load takes longer than ParserFunctions.
If A or B or C (resolved)
I am trying to use the if statement to test for multiple different values.
For example:
{{#if: {{{a|}}}{{{b|}}}{{{c|}}}| YES | NO}}
would display "YES" if any of the three (a,b,c) variables were defined. If, and only if, all 3 were NOT defined, it would display "NO".
I simply cannot get this to work! Any help would be most appreciated.
--Zackmann08 (talk) 01:09, 10 September 2012 (UTC)
- Try it like this
{{#if:{{{a|}}}|YES|{{#if:{{{b|}}}|YES|{{#if:{{{c|}}}|YES|NO}}}}}}
. If one of the parameters has a value it will display YES, only when non of the parameters has a value it will display NO. In this way you can make any combination you want and make it as complicated as you want. --Jongfeli (talk) 09:03, 10 September 2012 (UTC)
- Try it like this
- The issue is that I am attempting to use this to do something much more complex than just displaying "YES" and "NO". I am using it to create a rather large table. Is there no way to do "If A or B or C"? --Zackmann08 (talk) 13:50, 10 September 2012 (UTC)
- If I understand you correctly you would like to fill a (calculated) column in a table and the value depends on other values in the same row? I tried this in combination with Extension:External Data but
{{#if:
does not work because it probably always gets a value back from the Query. It does not matter if there is a database NULL in the table or an empty string. Just to see if it can work I tried{{#ifeq:
(see example below) but it only works on the first row it displays, if in the first row a = 1 it will display Yes and it will repeat the result on the rest of the rows even if a is not 1.
- If I understand you correctly you would like to fill a (calculated) column in a table and the value depends on other values in the same row? I tried this in combination with Extension:External Data but
{{#for_external_table:expression}} {| class = "wikitable" ! Column 1 ! Column 2 ! Column 3 ! Test{{#for_external_table:<nowiki/> {{!}}- !{{{a}}} {{!}}{{{b}}} {{!}}{{{c}}} {{!}}{{#ifeq:{{{a}}}|1|Yes|No}} }}
- Maybe I am doing something wrong but it seems that in combination with External Data the ParserFunctions does not handle each row individually. --Jongfeli (talk) 15:19, 10 September 2012 (UTC)
- This is part of an infobox. I am trying to copy the technique used on wikipedia (For example: http://en.wikipedia.org/w/index.php?title=Template:Infobox_weapon&action=edit)
- In the example below, the heading for the "Service History" only displays if "service", "used_by" or "wars" is defined. For some reason, this exact syntax is not working for me.
<!------------------------------Service history------------------------------> {{#if:{{{service|}}}{{{used_by|}}}{{{wars|}}} | ! colspan="2" {{WPMILHIST Infobox style|header_bar}} {{!}} Service history }} |- {{#if:{{{service|}}} | ! style="padding-right: 1em;" {{!}} In service {{!}} {{{service|}}} }} |- {{#if:{{{used_by|}}} | ! style="padding-right: 1em;" {{!}} Used by {{!}} {{{used_by|}}} }} |- {{#if:{{{wars|}}} | ! style="padding-right: 1em;" {{!}} Wars {{!}} {{{wars|}}} }} |-
- So its now working. Not sure what i was doing wrong... Oh well! --Zackmann08 (talk) 16:26, 10 September 2012 (UTC)
If number check (resolved)
I am attempting to write an error checking function that checks to see whether a user has supplied either a year (####) or the word "Present". (This is for an infobox for a vehicle. I want to display the production years.) I am 99% of the way there with the following:
{{#iferror:{{#expr: 0 + {{{1}}}}}|{{#ifeq:{{{1}}}|Present|<!--DO NOTHING-->|<!--Display some error message-->}}}}
The issue that I am having is that if a valid date is supplied, then the expression ({{#expr: 0 + {{{1}}}}}) evaluates and is displayed. Is there an easy way to suppress that expression? I seem to remember seeing a "span display=none" type thing somewhere...
Any advice will be greatly appreciated.
--Zackmann08 (talk) 14:35, 19 September 2012 (UTC)
- I love solving my own problems. :-) <span Style="display: None"> was my solution. --Zackmann08 (talk) 14:40, 19 September 2012 (UTC)
- I also had a similar question because the parser functions give script errors in some cases. I had do this. --Rical (talk) 22:50, 19 September 2012 (UTC)