Template:If blank
From Historical Hastings
Purpose: when used as a template output for a query, makes show statements more readable. As a disadvantage, it handles only inline results with a single report property.
Discussion:
The inline query parameter "default" is somewhat nonintuitive. It does not fire when there is no text, it fires when the query portion of the statement fails. They are not the same. Consider the following example article that does not have a birth locality property set:
- {{#show:Abraham Hunsberger (1786-1860)|default=unknown locality|?birth locality}} returns "unknown locality"
- This query does not display "unknown locality" as one might suspect. Instead it displays a null. This is because the query portion actually succeeded. There is indeed an article "Abraham Hunsberger (1786-1860)", so for that reason default text was not invoked. To get default to fire, we must construct a query that will fail. We ask for birth locality to also have some value.:
- {{#ask:[[Abraham Hunsberger (1786-1860)]] [[birth locality::+]]|default=unknown locality|?birth locality}} returns "unknown locality"
- This presents intimidating syntax for contributors. It would be possible to do a template such as
- {{#show:Abraham Hunsberger (1786-1860)|template=if blank{{!}}return=unknown locality|?birth locality}} returns ""
- Where template {{if blank}} simply prints value of parameter "return" if there result of the query is blank.
| The above documentation is transcluded from Template:If blank/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |