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