Last modified: 2010-05-15 15:37:28 UTC
It would be nice if there were to be an IFDEF-like method for template parameter expansion Example: Parameter #1 is {{{ifndef:1|not}}} defined{{{ifdef:1|, and is set to: {{{1}}}}}}.
See also bug 364.
It would be VERY nice to have an ifdef-like method, particularly for citations. The citation templates are exploding with so many variants you can't keep track of them. (One template if there's an author and date... a different one if no date... etc. etc. etc.). Just have a "default" isn't enough, because you often want OTHER text but ONLY if a given template parameter is defined. Suggested syntax: {{{?name ...replaceable text... }}} If "name" is defined, then use "replaceable text" (which may have normal text, template parameter references, and so on) If "name" is undefined, it has 0 length. {{{!name ... replaceable text...}}} The inverse of "?". If name is NOT defined, then use "replaceable text"... if name IS defined, then it has 0 length. Combining the two gives you an if...else, but you don't have to put them in the same place. --- David A. Wheeler
The funny thing is that we already have ifndef: {{{A|B}}} is equivalent to ifndef(A) then "B", as long as A is either undefined or empty, i.e. something like either {{pictureframe}} or {{pictureframe|notitle=}}. This is, of course, cumbersome, as are extensions of syntax everybody is proposing. What I think would be better to extend the {{{arg}}} syntax to 3 forms, the first two of which already exist: {{{A}}} = print A {{{A|B}}} = ifdef A print A else print B, where B can be empty {{{A|B|C}}} = ifdef A print B else print C, where both B and C can be empty That would be a natural extension of the current syntax: it would make {{{A}}} a shorthand for {{{A|A|A}}}, and {{{A|B}}} a shorthand for {{{A|A|B}}}.
Hallo! There are two similar requirements which differ by object type. {{{A|B|C}}} = ifdef A print B else print C, where both B and C can be empty I suppose that *A* in this case is regarded as a *parameter*. at bug 2299 comment 5 ( http://bugzilla.wikimedia.org/show_bug.cgi?id=2299#c5 ) *A* is a *page* in the database; *exists* was used not *defined*; IFEXISTS [[{{NAMESPACE}}:{{PAGENAME}}/archive]] THEN <code> where code could be [[{{NAMESPACE}}:{{PAGENAME}}/archive|archive]] and IFNOTEXISTS [[{{NAMESPACE}}:{{PAGENAME}}/to do/priority]] THEN <code>
In common dayly language there are two meanings which can be associated with "IFDEF" in connection with template parameters a) If "parameter is present" when the template is called at one page you write {{template_a|PARAMETER_IS_PRESENT=foo}} at another {{template_a}} b) if the parameter has a value other then the empty string (eventualy being NULL) {{template_a|PARAMETER_IS_PRESENT=}} It is not easy to say whay "IFDEF" should be.
"IFDEF" should probably have the meaning (a) above, to be consistent with the way parameter defaults work. A plain "IF" could, if desired, be used for meaning (b).
The problem with your proposals is that you can't have | as an argument, so you won't be able to create a row in a wikitable. I made a simple logic code, perhaps using the "if-part of it as a extension?) See for your self: http://meta.wikimedia.org/wiki/User:AzaToth/Logic The way it works is to ignore the wiki-code, and act as a preprocessor, using {#..#} as definition, and as default | is delimiter per arguments, but can be overrided by placing [delimiter] aftyer the first #, for example {#[$]if$foo$!header$|row#}
(In reply to comment #7) > The problem with your proposals is that you can't have | as an argument, so you > won't be able to create a row in a wikitable. Is there a reason why "{{ifdef:foo | Some|Wiki|markup|with|vertical|bars.}}" could not be made to work as expected? I'm not familiar enough with MediaWiki internals myself, but it shouldn't be impossible, should it? Even if some code automatically splits on "|", couldn't the fragments just be concatenated again?