Knowledge (XXG)

Template:When pagename is

Source 📝

35: 605: 598: 148:| User:Example/test = Text for "User:Example/test". | User:Example = Text for "User:Example". | User talk:Example = Text for "User talk:Example". 1084: 156:| Example = Matches "User:Example", "User talk:Example", "Template:Example" and so on, but not "User:Example/something". 591: 1069: 160:| User:Example/* = Matches "User:Example/something", but not "User:Example". | User talk:Example/* = Matches "User talk:Example/something". 1057: 50: 1096: 1053: 46: 208:
If an empty (but defined) parameter matches, the matching stops and the template returns an empty string. That's on purpose and can be used like this:
79:
This template takes one or more parameters. Most of the parameters don't have fixed names, instead they are part of the pattern matching. Like this:
1117: 54: 503:
This template doesn't have namespace matching. If you need that then combine this template with one of the namespace-detection templates such as
444:
parameter. That means you can demonstrate the different appearances of your template in the documentation for your template. Then do like this:
172:| /some* = Any subpage name beginning with "/some" or "/Some". | /arch* = Matches "User talk:Example/Archive 1". 322:" must be lower case. But it matches subpage names in both upper and lower case such as "User:Example/SomeThing" and "User:Example/something". 1079: 1122: 1039: 1064: 728: 1112: 955: 578: 507: 187:
There's no limit to the number of parameters that you can use, other than what the servers and MediaWiki system can handle.
1092: 1047: 738: 42: 168:| /something = Any pagename that ends in "/something". | /doc = Any pagename that ends in "/doc". 1025: 430:
parameter makes this template behave exactly as if on that page. The pagename doesn't have to be an existing page.
557:
If on "User:Example/doc" the code above will return nothing. But if on "Template:Example/doc" it will return this:
967: 943: 768: 745: 723: 697: 860: 733: 702: 71:
meta-template. It helps other templates detect what page they are on, using pattern matching on the pagename.
707: 907: 872: 682: 645: 848: 836: 824: 692: 253:
The code above will render nothing when on a /doc page. But when on a /sandbox page it will return this:
1015: 1010: 759: 620: 677: 672: 176:| basepage = Text for any basepage. | subpage = Text for any subpage. | other = Text for any page. }} 164:| Example/* = Matches "User:Example/something" and "User talk:Example/something". 650: 919: 895: 687: 667: 660: 655: 640: 635: 979: 1043: 991: 583: 812: 1020: 570:
This template detects subpages even when used in namespaces that don't have the MediaWiki
931: 152:| User:Example/+ = Matches "User:Example" and "User:Example/test". 1106: 571: 437:
parameter is empty or undefined, the name of the current page determines the result.
356:" are defined, and the current page is "User:Example/Something", then the data from " 180:
The matching goes from top to bottom, and returns the first parameter that matches. "
17: 961:
Displays different content to extended confirmed and non-extended confirmed users.
325:
The partial matching only supports matching on 4, 6 and 8 characters. Thus using "
800: 368:
For testing and demonstration purposes this template can take a parameter named
184:" means the order shown above, not the order you happen to feed the parameters. 150:<!-- Match on full basepage name, when on a basepage or its subpages --> 115:
If the template is on "Template:Example/doc" the code above will return this:
418:
No matter on what kind of page the code above is used it will return this:
29: 949:
Displays different content to autoconfirmed and non-autoconfirmed users.
818:
Returns IP-user talkpage, registered-user talkpage or non-user talkpage.
997:
Detects whether page is viewed with a JavaScript-capable client or not.
274:
This template can also match on partial subpage names. Like this:
310:
If on "User:Example/Archive 1" the code above will return this:
587: 170:<!-- Match on partial subpage name (case-insensitive) --> 574:
enabled. Thus this template works the same in all namespaces.
985:
Displays different content to mobile users and desktop users.
158:<!-- Match on full basepage name, when on a subpage --> 901:
Detects whether it is on a page with a stub template or not.
194:" matches "User:Example/test" but not "User:Example/Test". 937:
Displays different content to IP users and logged-in users.
806:
Can take apart and put together pagenames in several ways.
774:
Detects and acts according to whether it is on a basepage
162:<!-- Match on basepage name, when on a subpage --> 1073: 440:
You can make it so your template also understands the
190:
Most of the matching is case-sensitive. For instance "
154:<!-- Match on pagename, when on a basepage --> 135:
Here is a description of the full pattern matching:
990: 978: 966: 954: 942: 930: 925:
Detects whether page is viewed as a preview or not.
918: 906: 894: 887: 871: 859: 847: 842:
Pagename has an after-slash part (not in mainspace)
835: 823: 811: 799: 787: 767: 758: 716: 628: 619: 878:Page is rootpage (vs. /subpage) (template space) 549:<!--(action if not on a Template: page)--> 261:And when on any other page it will return this: 599: 8: 913:Detects whether it is on a redirect or not. 866:Page is subpage /testcases (template space) 348:Longer patterns match first, thus if both " 197:Matching on partial subpage names such as " 127:page than a /doc page it will return this: 1063:Editors can experiment in this template's 891: 764: 625: 614:Namespace and pagename-detecting templates 606: 592: 584: 202: 854:Page is subpage /sandbox (template space) 794:For pattern matching on the pagename. 146:<!-- Match on full pagename --> 7: 577:For more technical details, see the 166:<!-- Match on subpage name --> 25: 973:Displays content only to admins. 33: 1118:Pagename manipulation templates 1: 1123:Knowledge (XXG) metatemplates 1048:Template:When pagename is/doc 830:For detecting IP-user pages. 201:" has some limitations, see 778:on any subpage (that is, a 541:Template doc page text. 1139: 1037: 123:If the template is on any 1097:Subpages of this template 1016:Knowledge (XXG):Page name 1011:Knowledge (XXG):Namespace 1006: 729:Namespace detect showall 515: 446: 374: 276: 210: 137: 81: 561:Template doc page text. 174:<!-- Defaults --> 1113:If-then-else templates 1091:Add categories to the 411:Template:Example/test 38:Template documentation 956:If extended confirmed 521:When on template page 508:When on template page 270:Partial subpage names 739:Main talk other flex 337:" works, but using " 318:The parameter name " 18:Template:If pagename 293:Archive page text 499:Namespace matching 473:Other pages text 401:Other pages text 1034: 1033: 1002: 1001: 883: 882: 754: 753: 566:Technical details 463:Test pages text 391:Test pages text 314:Archive page text 303:Other pages text 246:Other pages text 108:Other pages text 16:(Redirected from 1130: 1088: 1077: 1061: 968:If administrator 944:If autoconfirmed 892: 789:When pagename is 781: 769:When on basepage 765: 746:Talkspace detect 724:Namespace detect 698:Single namespace 626: 608: 601: 594: 585: 553: 550: 547: 544: 540: 537: 534: 531: 530:When pagename is 528: 525: 522: 519: 512: 506: 494: 491: 488: 485: 482: 479: 476: 472: 469: 466: 462: 459: 456: 453: 452:When pagename is 450: 414: 410: 407: 404: 400: 397: 394: 390: 387: 384: 381: 380:When pagename is 378: 364:"page" parameter 360:" will be used. 359: 355: 351: 345:" doesn't work. 344: 340: 336: 332: 328: 321: 306: 302: 299: 296: 292: 289: 286: 283: 282:When pagename is 280: 265:Other pages text 249: 245: 242: 239: 235: 232: 229: 226: 223: 220: 217: 216:When pagename is 214: 200: 193: 175: 171: 167: 163: 159: 155: 151: 147: 144: 143:When pagename is 141: 131:Other pages text 111: 107: 104: 101: 97: 94: 91: 88: 87:When pagename is 85: 70: 66:When pagename is 64: 58: 39: 37: 36: 21: 1138: 1137: 1133: 1132: 1131: 1129: 1128: 1127: 1103: 1102: 1101: 1100: 1090: 1082: 1067: 1062: 1051: 1036: 1035: 1030: 1026:ParserFunctions 998: 986: 974: 962: 950: 938: 926: 914: 902: 879: 867: 861:Testcases other 855: 843: 831: 819: 807: 795: 783: 779: 750: 734:Main talk other 712: 703:If talkspace of 615: 612: 572:subpage feature 568: 555: 554: 551: 548: 545: 542: 538: 535: 532: 529: 526: 523: 520: 517: 510: 504: 501: 496: 495: 492: 489: 486: 483: 480: 477: 474: 470: 467: 464: 460: 457: 454: 451: 448: 422:Test pages text 416: 415: 412: 408: 405: 402: 398: 395: 392: 388: 385: 382: 379: 376: 366: 357: 353: 349: 342: 338: 334: 330: 326: 319: 308: 307: 304: 300: 297: 294: 290: 287: 284: 281: 278: 272: 251: 250: 247: 243: 240: 237: 233: 230: 227: 224: 221: 218: 215: 212: 203:its own section 198: 191: 178: 177: 173: 169: 165: 161: 157: 153: 149: 145: 142: 139: 113: 112: 109: 105: 102: 99: 95: 92: 89: 86: 83: 77: 68: 62: 59: 40: 34: 32: 27: 23: 22: 15: 12: 11: 5: 1136: 1134: 1126: 1125: 1120: 1115: 1105: 1104: 1032: 1031: 1029: 1028: 1023: 1018: 1013: 1007: 1004: 1003: 1000: 999: 996: 994: 988: 987: 984: 982: 976: 975: 972: 970: 964: 963: 960: 958: 952: 951: 948: 946: 940: 939: 936: 934: 928: 927: 924: 922: 916: 915: 912: 910: 908:Redirect other 904: 903: 900: 898: 889: 885: 884: 881: 880: 877: 875: 873:Rootpage other 869: 868: 865: 863: 857: 856: 853: 851: 845: 844: 841: 839: 833: 832: 829: 827: 821: 820: 817: 815: 809: 808: 805: 803: 797: 796: 793: 791: 785: 784: 773: 771: 762: 756: 755: 752: 751: 749: 748: 743: 742: 741: 731: 726: 720: 718: 714: 713: 711: 710: 708:If usertalk of 705: 700: 695: 690: 685: 683:Template other 680: 675: 670: 665: 664: 663: 653: 648: 646:Category other 643: 638: 632: 630: 623: 617: 616: 613: 611: 610: 603: 596: 588: 567: 564: 563: 562: 516: 500: 497: 447: 424: 423: 375: 365: 362: 316: 315: 277: 271: 268: 267: 266: 259: 258: 236:Sandbox text 211: 138: 133: 132: 121: 120: 98:Doc page text 82: 76: 73: 31: 30: 24: 14: 13: 10: 9: 6: 4: 3: 2: 1135: 1124: 1121: 1119: 1116: 1114: 1111: 1110: 1108: 1098: 1094: 1086: 1081: 1075: 1071: 1066: 1059: 1055: 1049: 1045: 1041: 1040:documentation 1027: 1024: 1022: 1019: 1017: 1014: 1012: 1009: 1008: 1005: 995: 993: 989: 983: 981: 977: 971: 969: 965: 959: 957: 953: 947: 945: 941: 935: 933: 929: 923: 921: 917: 911: 909: 905: 899: 897: 893: 890: 886: 876: 874: 870: 864: 862: 858: 852: 850: 849:Sandbox other 846: 840: 838: 837:Subpage other 834: 828: 826: 825:IP-user other 822: 816: 814: 810: 804: 802: 798: 792: 790: 786: 777: 772: 770: 766: 763: 761: 757: 747: 744: 740: 737: 736: 735: 732: 730: 727: 725: 722: 721: 719: 715: 709: 706: 704: 701: 699: 696: 694: 693:Project other 691: 689: 686: 684: 681: 679: 676: 674: 671: 669: 666: 662: 659: 658: 657: 654: 652: 649: 647: 644: 642: 639: 637: 634: 633: 631: 627: 624: 622: 618: 609: 604: 602: 597: 595: 590: 589: 586: 582: 580: 575: 573: 565: 560: 559: 558: 514: 513:. Like this: 509: 498: 445: 443: 438: 436: 431: 429: 421: 420: 419: 373: 372:. Like this: 371: 363: 361: 346: 323: 313: 312: 311: 275: 269: 264: 263: 262: 256: 255: 254: 209: 206: 204: 195: 188: 185: 183: 182:Top to bottom 136: 130: 129: 128: 126: 119:Doc page text 118: 117: 116: 80: 74: 72: 67: 56: 52: 48: 44: 28: 19: 788: 775: 717:More generic 678:Portal other 673:Module other 576: 569: 556: 511:}} 505:{{ 502: 441: 439: 434: 432: 427: 425: 417: 369: 367: 347: 324: 317: 309: 273: 260: 257:Sandbox text 252: 207: 196: 189: 186: 181: 179: 134: 124: 122: 114: 78: 69:}} 65: 63:{{ 61:This is the 60: 26: 1044:transcluded 1021:Magic words 801:Module:Page 651:Draft other 53:] [ 49:] [ 45:] [ 1107:Categories 1038:The above 920:If preview 896:Stub other 688:User other 668:Help other 661:Is Commons 656:File other 641:Talk other 636:Main other 629:Particular 358:/somethin* 350:/somethin* 335:/somethin* 1095:subpage. 1080:testcases 980:If mobile 782:subpage). 621:Namespace 579:talk page 288:/archiv* 231:/sandbox 992:Noscript 760:Pagename 331:/someth* 1072:| 1065:sandbox 1058:history 1056:| 813:IP-talk 433:If the 352:" and " 343:/somet* 333:" and " 205:below. 51:history 1089:pages. 888:Others 468:other 458:/test 396:other 386:/test 354:/some* 341:" or " 327:/some* 320:/some* 298:other 241:other 199:/some* 103:other 1046:from 932:If IP 780:../.. 536:/doc 478:page 406:page 339:/som* 222:/doc 192:/test 125:other 93:/doc 75:Usage 57:] 55:purge 41:[ 1093:/doc 1085:edit 1078:and 1074:diff 1070:edit 1054:edit 490:|}}} 487:page 442:page 435:page 428:page 426:The 370:page 329:", " 47:edit 43:view 1042:is 484:{{{ 1109:: 1050:. 776:or 581:. 552:}} 543:}} 527:{{ 518:{{ 493:}} 449:{{ 413:}} 377:{{ 305:}} 279:{{ 248:}} 213:{{ 140:{{ 110:}} 84:{{ 1099:. 1087:) 1083:( 1076:) 1068:( 1060:) 1052:( 607:e 600:t 593:v 546:| 539:= 533:| 524:| 481:= 475:| 471:= 465:| 461:= 455:| 409:= 403:| 399:= 393:| 389:= 383:| 301:= 295:| 291:= 285:| 244:= 238:| 234:= 228:| 225:= 219:| 106:= 100:| 96:= 90:| 20:)

Index

Template:If pagename
view
edit
history
purge
When pagename is
its own section
When on template page
subpage feature
talk page
v
t
e
Namespace
Main other
Talk other
Category other
Draft other
File other
Is Commons
Help other
Module other
Portal other
Template other
User other
Project other
Single namespace
If talkspace of
If usertalk of
Namespace detect

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.