Add an "IFDEF" operator for template inclusion
Closed, ResolvedPublic

Description

Author: en.ABCD

Description:
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}}}}}}.


Version: 1.5.x
Severity: enhancement

bzimport added a project: MediaWiki-Templates.Via ConduitNov 21 2014, 8:38 PM
bzimport added a subscriber: Unknown Object (MLST).
bzimport set Reference to bz2615.
bzimport created this task.Via LegacyJun 29 2005, 7:57 PM
brion added a comment.Via ConduitJun 29 2005, 8:50 PM

See also bug 364.

bzimport added a comment.Via ConduitOct 19 2005, 4:28 PM

dwheeler wrote:

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
bzimport added a comment.Via ConduitNov 25 2005, 3:26 PM

zocky wrote:

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}}}.

bzimport added a comment.Via ConduitNov 25 2005, 5:11 PM

gangleri wrote:

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>

bzimport added a comment.Via ConduitNov 25 2005, 6:21 PM

gangleri wrote:

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.

Ilmari_Karonen added a comment.Via ConduitJan 7 2006, 8:43 PM

"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).

AzaToth added a comment.Via ConduitJan 7 2006, 9:53 PM

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#}

Ilmari_Karonen added a comment.Via ConduitJan 7 2006, 10:48 PM

(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?

Add Comment