It details processes or procedures of some aspect(s) of Wikipedia's norms and practices. It is not one of Wikipedia's policies or guidelines, and may reflect varying levels of consensus and vetting.
Shortcut
WP:ADTEMPLATE
There are some advanced template coding techniques to improve the display or editing of templates in Wikipedia. There are also some tactics for debugging template parameters in the MediaWikimarkup language. If there is a possibility, it is better to use lua modules.
Many bugs are associated with the difficulty in dealing with some awkward features in the markup language which lead to coding errors. Unbalanced metacharacters are a major source of errors. For example, coding {{1}}} instead of {{{1}}} causes it to act as if it were {{1}} }, thereby invoking Template:1 + "}".
There are some differences of wiki-formatting of contents of parameters when inside #if-expressions, but not when outside. Templates which need to be substituted need special handling. Providing parameter defaults or parameter aliases is covered as well.
Nesting levels limited to 40edit
Inside a single template, the nesting limit is 40 nested expressions, such as 40 multiple "if-then-else-if...". At the 41st nested "if" keyword an error message might appear, as: "Exceeded nesting limit". However, when not nested beyond 40 levels, a template can contain hundreds of if-expressions and switch-branches, but not all nested inside the others.
Some templates have contained complex conditional calculations nested over 23 levels deep, for years. Also, some templates have contained hundreds of if-expressions, for years, just NOT all nested as one, giant: if-then-else-else-else-else-else....
MediaWiki wiki-formats the clauses inside #ifedit
An issue which complicates template processing, for parameters, is the wiki-formatting of parameter contents when inside of if-logic (such as #if or #ifeq) or #switch (or lc:, lcfirst:, uc:, ucfirst:). As of May 2012[update], the MediaWiki markup parser is still wiki-formatting the contents of parameters when inside #if-expressions (but not outside). This means that parameters containing spaces, lead semicolon, colon (":") or pound sign ("#") can change their values while inside the if-clauses (surprise!). So, for example, a parameter {{{4}}} when outside an #if can display differently than inside {{#ifeq:{{{1}}}=0|{{{4}}} ...}}. The worst shock is when parameter 4 contains a leading semicolon, which triggers formatting to become ye-olde bolded semicolon-header line:
TEST 1: {{#if:{{{4|}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 2: {{#if:{{{4|;}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 1: no, 4=empty
TEST 2:
<== yes, semicolon
<== Separate example of semicolon-header
The problem occurs whether inside of #if, #ifexpr, #ifeq or #switch markup expressions. If the parameter is preceded by text, in either of the then/else clauses, then the wiki-formatting inside the parameter does not occur.
TEST 3: {{#ifexpr:{{{1|7}}}=7|<b></b>{{{4|;}}} equals 7|not 7}}
TEST 4: {{#ifexpr:{{{1|7}}} < 9|{{{4|#}}} LESS THAN 9|not<9}}
TEST 5: {{#ifexpr:{{{1|7}}} < 9| {{{4|#}}} LESS THAN 9|not<9}}
TEST 6: "{{#ifexpr:{{{1|7}}} < 9| {{{4|#}}} LESS THAN 9|not<9}}"
TEST 3: ; equals 7
TEST 4:
LESS THAN 9
TEST 5: # LESS THAN 9
TEST 6: " # LESS THAN 9"
In TEST 4, the leading pound sign "#" triggered auto-numbering of the line (indented with "1."). The situation of having a leading semicolon, colon or "#" might be relatively rare, but this is just a reminder: for showing the true contents of a template parameter, try to display a parameter outside the start of any if-statement clauses, or display other text before the parameter inside the if-logic, or else prepare for some shocking results when a parameter is wiki-formatted for display inside the if-logic.
If the result of #if, etc. is not intended to be formatted, using #, :, and ; instead of #, :, and ; will work fine.
TEST 7: {{#ifexpr:{{{1|7}}} < 9|{{{4|#}}} LESS THAN 9|not<9}}
TEST 7: # LESS THAN 9
Debuggingedit
Many coding errors can be debugged, more easily, by attempting to isolate the code section where coding errors most likely occurred. Intense proofreading, of the logic flow, is most often the quickest fix, such as checking for typical syntax errors (see below: "Common coding errors"). Sometimes, a section of troublesome code could be copied into a short test page, then by edit-preview, tested there, separately. However, if editing that extra-page window seems like too much effort, then consider merely copying the code to the top of the current template. Similarly, a template could be developed, in the early stages, as multiple sections of code, each to be debugged separately, then eventually joined together, such as nested sections with if-then-else-if.
As a review of those options, consider:
Try carefully proofreading troublesome code, matching "{{" with "}}". (consider using Equazcion's syntax highlighter for Notepad++)
Copy a template section into a test-page edit-window, for debug.
Copy a template section to the top of the template, for debug.
Restructure a template so that each section is more separated.
The basic strategy: isolate the code section to be debugged.
Next, the testing, of each section of code, is crucial. There are some age-old adages to heed:
Perhaps put a variety of examples on each template's doc subpage, to help detect problems early in development. However, for complex templates, then the talk-page, or a special subpage "/testcases", should contain a section of numerous examples (a whole lot of them) to demonstrate the full scope of template features.
Defaulting parameters in expressions and if-logicedit
When developing sections of markup that use template parameters, try to always set each parameter with a default value, especially inside expressions or if-logic coding:
{{#expr: 109.75 / {{{1|1}}}}} → default {1} as 1 not zero.
{{#ifeq:{{{answer|y}}}|y|show yes}}
If a particular parameter is given the same default value across the whole page, then that value could be easily changed, in a text editor, by a global search-and-replace string substitution, to change the default value to some other value, for testing each case.
If those parameters are not given default values, then those sections of code cannot be tested, during edit-preview, while editing the template. Any parameter without a default value will become the literal triple-brace text (such as the literal 7 characters: {{{x}}}), and non-defaulted parameters cannot be evaluated, in expressions or if-logic, during an edit-preview of the template page.
Common coding errorsedit
There are several common coding errors which will cause problems when processing templates. The following can be used as a checklist, to help debug problems, when a template seems to be acting bizarre:
Too few closing braces: A common problem is to put only 2 closing-braces around a parameter number or name, such as {{{1}}. Having only 2 closing-braces }} might treat the parameter as a template named "Template:1" (preceded by a lone "{" brace).
Unopened comments: Forgetting to insert <!-- at the start of an HTML comment can cause bizarre results, with no error message. Forgetting the exclamation point is very common: <-- should be <!--.
Unclosed comments: Forgetting to insert --> at the end of an HTML comment can cause bizarre results, with no error message.
Omitting colon or "#" on "#ifexpr": Forgetting to insert "#" or colon for "#ifexpr:" or "#expr:" can produce bizarre results, when passed into other subtemplates.
Note that those common coding errors could have been easily spotted by a simple syntax checker, such as warning that 3&2 braces could be trouble: {{{size|180px}} is treated as "{Template:Size" trying to pass 180px as the parameter because of only 2 end-braces.
Again, always checking first for common errors, as the first step, can avoid time hunting for "complex errors" which never really existed. Remember: the MediaWiki markup language is extremely error-prone, so that's why so many coding errors occur, and that's why:
Consider the above as a checklist to try first, as a type of sanity-check for the template.
Many hideous problems truly are merely 1-minute syntax fixes.
Coding a template to allow WP:SUBST substitutionedit
Shortcut
WP:SUBSTALLOW
In rare cases, a template might need to be rewritten to allow text substitution (per WP:SUBST), where the results of running a template will be saved into the page during an edit-SAVE operation. In that case, the safesubst-prefix must be inserted into every markup function used inside that template, at every level of nested logic. Also, every HTML comment must be surrounded by "noinclude" tags: <noinclude><!--HTML comment HERE--></noinclude>.[a] Otherwise, all of the triggered HTML comments will be stored inside the SAVEd page, in the sequence executed by running the template. NOTE: All the extra "noinclude" and safesubst:<noinclude/> keywords will likely require the template's markup to be re-indented inside, to fit all that extra inserted text, which will widen and clutter the original markup style.
Specifically, to alter a template to allow text substitution, then the prefix safesubst:<noinclude/> must be inserted inside the opening double-brace {{ of each markup function inside that template. Some examples of inserting the safesubst-prefix inside a template's markup:
Total articles now: {{NUMBEROFARTICLES}} → 6,803,976
Total articles was: {{subst:NUMBEROFARTICLES}} → 3,953,715
{{safesubst:<noinclude/>#ifeq:{{{1|AX}}}|AX|yes}}
{{safesubst:<noinclude/>lc:THIS LOWERCASE TEXT}} → this lowercase text
In general, every markup function which starts with double-brace {{ must be altered to insert the long safesubst-prefix safesubst:<noinclude/> (with no space afterward).[b] The action of keyword "safesubst" is to allow conditional substitution of markup, when the whole template is invoked as {{subst:MyTemplate|...}}. In essence, the keyword "safesubst" could be called "ifsubst" as meaning, "if 'subst:' was used to invoke this template, then substitute here as well".
Remember: The safesubst-prefix must be inserted into every markup function inside that template, except for test logic never used in an actual page. Any markup which omits "safesubst" will fail if the template is executed by the subst mode, "{{subst:MyTemplate|...}}". Parameters are not changed, so {{{1}}} would remain unchanged, without a safesubst-prefix.
Exceptions: Only logic which would never be stored in a page could omit "safesubst", such as test-logic which is triggered by special parameter values never used inside a stored page. Any markup which omits "safesubst" will only work during regular transclusion but fail if the template is executed by using the subst-mode prefix "subst:". For more examples, and further technical explanations, see: WP:Substitution.
Indenting the long lines: All of the added safesubst-prefix text will widen lines, so to improve readability, they could be split and indented before any of the safesubst:<noinclude/> prefixes. For example:
{{safesubst:<noinclude/>#ifeq:{{ safesubst:<noinclude/>padleft:|1|{{{1}}} }}|A|Begins with "A"}}
In that indentation style, the text "safesubst:<noinclude/>" begins the next line. Avoid wrapping a line after the prefix safesubst:<noinclude/> because several markup functions might fail to work correctly unless the safesubst prefix is immediately attached before the keyword, such as {{ safesubst:<noinclude/>#ifeq:...}}
Examples of very large templatesedit
When trying to perform more-complex, or intricate, operations, there might be an instinctive fear that templates cannot be as large as needed. However, there are many very large templates which have been running, for years, on Wikipedia, for example:
Template:Citation/core - formats 621 source-reference parameters into standardized form
Template:Infobox settlement - formats various town/region infoboxes in consistent form
The source-footnote formatter, Template:Citation/core, displays a standardized citation format, as invoked by several wrapper templates which pass hundreds of parameters, where the core logic checks 621 parameter values, in the conditional markup expressions.
Try some programmingedit
The Special:ExpandTemplates page takes some wikitext and expands everything in double braces recursively: templates, parser functions like {{#if:...}}, and variables like {{CURRENTDAY}}
See alsoedit
WP:Category suppression
WP:Advanced article editing
WP:Advanced footnote formatting
WP:Advanced table formatting
WP:Advanced text formatting
WP:Thinking outside the infobox
WP:Alert
Help:Punctuation
WP:Wikimedia Foundation error
WP:About translating German Wikipedia
WP:Lua
{{if}} and {{Ifequal}}.
Template:Wrapper template
m:Help:Calculation
Notesedit
^But if you want the HTML comment to appear, as is the case, for example, with User warning templates, then do not enclose the HTML comment in <noinclude> tags.
Search for pattern ([^{]){{([^{]) and replace it with \1{{ safesubst:<noinclude/>\2
Or, in one step, for one style of regex :
s/([^{]){{([^{])/\1{{ safesubst:<noinclude/>\2/g
You might need to break up long lines; see "Indenting the long lines" in this section. As a practical matter, it's easier to join lines of code than to break them, so if you replace the blank in the replace-pattern above with a newline (plus optional white space) instead, it will break lines with every substitution; when it's done, just go back and join any lines that are too short.
v
t
e
Wikipedia essays (?)
Essays on building, editing, and deleting content
Philosophy
Article content
Articles must be written
All Five Pillars are equally important
Avoid vague introductions
Be a reliable source
Civil POV pushing
Cohesion
Competence is required
Concede lost arguments
Dissent is not disloyalty
Don't lie
Don't search for objections
Editing Wikipedia is like visiting a foreign country
Editors will sometimes be wrong
Eight simple rules for editing our encyclopedia
Explanationism
External criticism of Wikipedia
Here to build an encyclopedia
Leave it to the experienced
Levels of competence
Most ideas are bad
Need
Neutrality of sources
Not editing because of Wikipedia restriction
The one question
Oversimplification
Paradoxes
Paraphrasing
POV and OR from editors, sources, and fields
Process is important
Product, process, policy
Purpose
Reasonability rule
Systemic bias
There is no seniority
Ten Simple Rules for Editing Wikipedia
Tendentious editing
The role of policies in collaborative anarchy
The rules are principles
Trifecta
Wikipedia in brief
Wikipedia is an encyclopedia
Wikipedia is a community
Wikipedia is not RationalWiki
Article construction
100K featured articles
Abandoned stubs
Acronym overkill
Adding images improves the encyclopedia
Advanced article editing
Advanced text formatting
Akin's Laws of Article Writing
Alternatives to the "Expand" template
Amnesia test
A navbox on every page
An unfinished house is a real problem
Articles have a half-life
Autosizing images
Avoid mission statements
Be neutral in form
Beef up that first revision
Blind men and an elephant
BOLD, revert, discuss cycle
Build content to endure
Cherrypicking
Chesterton's fence
Children's lit, adult new readers, & large-print books
Citation overkill
Citation underkill
Common-style fallacy
Concept cloud
Creating controversial content
Criticisms of society may be consistent with NPOV and reliability
Deprecated sources
Dictionaries as sources
Don't demolish the house while it's still being built
Don't get hung up on minor details
Don't hope the house will build itself
Don't panic
Don't "teach the controversy"
Editing on mobile devices
Editors are not mindreaders
Encourage the newcomers
Endorsements (commercial)
Featured articles may have problems
Formatting bilateral relations articles
Formatting bilateral relations templates
Fruit of the poisonous tree
Give an article a chance
How to write a featured article
Identifying and using independent sources
History sources
Law sources
Primary sources
Science sources
Style guides
Tertiary sources
Ignore STRONGNAT for date formats
Inaccuracy
Introduction to structurism
Mine a source
Merge Test
Minors and persons judged incompetent
"Murder of" articles
Not every story/event/disaster needs a biography
Not everything needs a navbox
Not everything needs a template
Nothing is in stone
Obtain peer review comments
Organizing disambiguation pages by subject area
Permastub
Potential, not just current state
Presentism
Principle of Some Astonishment
The problem with elegant variation
Pro and con lists
Printability
Pruning article revisions
Publicists
Put a little effort into it
Restoring part of a reverted edit
Robotic editing
Sham consensus
Source your plot summaries
Specialized-style fallacy
Stub Makers
Run an edit-a-thon
Temporary versions of articles
Tertiary-source fallacy
There are no shortcuts to neutrality
There is no deadline
There is a deadline
The deadline is now
Try not to leave it a stub
Understanding Wikipedia's content standards
Walled garden
What an article should not include
Wikipedia is a work in progress
Wikipedia is not a reliable source
Wikipedia is not being written in an organized fashion
The world will not end tomorrow
Write the article first
Writing better articles
Writing article content
Avoid thread mode
Copyediting reception sections
Coup
Don't throw more litter onto the pile
Gender-neutral language
Myth vs fiction
Proseline
Use our own words
We shouldn't be able to figure out your opinions
Write the article first
Writing about women
Writing better articles
Removing or deleting content
Adjectives in your recommendations
AfD is not a war zone
Arguments to avoid in deletion discussions
Arguments to avoid in deletion reviews
Arguments to avoid in image deletion discussions
Arguments to make in deletion discussions
Avoid repeated arguments
Before commenting in a deletion discussion
But there must be sources!
Confusing arguments mean nothing
Content removal
Counting and sorting are not original research
Delete or merge
Delete the junk
Deletion is not cleanup
Does deletion help?
Don't attack the nominator
Don't confuse stub status with non-notability
Don't overuse shortcuts to policy and guidelines to win your argument
Follow the leader
How to save an article proposed for deletion
I just don't like it
Identifying blatant advertising
Identifying test edits
Immunity
Keep it concise
Liar liar pants on fire
Nothing
Nothing is clear
Overzealous deletion
Relisting can be abusive
Relist bias
The Heymann Standard
Unopposed AFD discussion
Wikipedia is not Whack-A-Mole
Why was the page I created deleted?
What to do if your article gets tagged for speedy deletion
When in doubt, hide it in the woodwork
No Encyclopedic Use
Essays on civility
The basics
Accepting other users
Apology
Contributing to complicated discussions
Divisiveness
Don't retaliate
Edit at your own pace
Encouraging the newcomers
Enjoy yourself
Expect no thanks
High-functioning autism and Asperger's editors
How to be civil
Maintaining a friendly space
Negotiation
Obsessive–compulsive disorder editors
Please say please
Relationships with academic editors
Thank you
Too long; didn't read
Truce
Unblock perspectives
We are all Wikipedians here
You have a right to remain silent
Philosophy
A weak personal attack is still wrong
Advice for hotheads
An uncivil environment is a poor environment
Be the glue
Beware of the tigers!
Civility warnings
Deletion as revenge
Failure
Forgive and forget
It's not the end of the world
Nobody cares
Most people who disagree with you on content are not vandals
Old-fashioned Wikipedian values
Profanity, civility, and discussions
Revert notification opt-out
Shadowless Fists of Death!
Staying cool when the editing gets hot
The grey zone
The last word
There is no Divine Right of Editors
Most ideas are bad
Nothing is clear
Reader
The rules of polite discourse
There is no common sense
Two wrongs don't make a right
Wikipedia clichés
Wikipedia is not about winning
Wikipedia should not be a monopoly
Writing for the opponent
Dos
Assume good faith
Assume the assumption of good faith
Assume no clue
Avoid personal remarks
Avoid the word "vandal"
Be excellent to one another
Beyond civility
Call a spade a spade
Candor
Deny recognition
Desist
Discussing cruft
Drop the stick and back slowly away from the horse carcass
Encourage full discussions
Get over it
How to lose
Imagine others complexly
Just drop it
Keep it concise
Keep it down to earth
Mind your own business
Say "MOBY"
Mutual withdrawal
Read before commenting
Settle the process first
Don'ts
ALPHABETTISPAGHETTI
Civil POV pushing
Cyberbullying
Don't accuse someone of a personal attack for accusing of a personal attack
Don't be a fanatic
Don't be a jerk
Don't be an ostrich
Don't be ashamed
Don't be a WikiBigot
Don't be high-maintenance
Don't be inconsiderate
Don't be obnoxious
Don't be prejudiced
Don't be rude
Don't be the Fun Police
Don't bludgeon the process
Don't call a spade a spade
Don't call people by their real name
Don't call the kettle black
Don't call things cruft
Don't come down like a ton of bricks
Don't cry COI
Don't demand that editors solve the problems they identify
Don't drink the consensus Kool-Aid
Don't eat the troll's food
Don't fight fire with fire
Don't give a fuck
Don't help too much
Don't ignore community consensus
Don't knit beside the guillotine
Don't make a smarmy valediction part of your signature
Don't remind others of past misdeeds
Don't shout
Don't spite your face
Don't take the bait
Don't template the regulars
Don't throw your toys out of the pram
Do not insult the vandals
Griefing
Nationalist editing
No angry mastodons
just madmen
No Nazis
No racists
No Confederates
No, you can't have a pony
Passive aggression
Please don't bite the newcomers
POV railroad
Superhatting
There are no oracles
There's no need to guess someone's preferred pronouns
You can't squeeze blood from a turnip
UPPERCASE
WikiRelations
WikiBullying
WikiCrime
WikiHarassment
WikiHate
WikiLawyering
WikiLove
WikiPeace
Essays on notability
Advanced source searching
All high schools can be notable
Alternative outlets
Arguments to avoid in deletion discussions
Articles with a single source
Avoid template creep
Bare notability
Big events make key participants notable
Businesses with a single location
But it's true!
Common sourcing mistakes
Clones
Coatrack
Discriminate vs indiscriminate information
Don't cite GNG
Drafts are not checked for notability or sanity
Every snowflake is unique
Existence ≠ Notability
Existence does not prove notability
Extracting the meaning of significant coverage
Google searches and numbers
High Schools
Inclusion is not an indicator of notability
Independent sources
Inherent notability
Insignificant
Masking the lack of notability
Make stubs
Minimum coverage
News coverage does not decrease notability
No amount of editing can overcome a lack of notability
No big loss
No one cares about your garage band
No one really cares
Notability/Historical/Arguments
Notability cannot be purchased
Notability comparison test
Notability is not a level playing field
Notability is not a matter of opinion
Notability is not relevance or reliability
Notability means impact
Notability points
Notability sub-pages
Notabilitymandering
Not every single thing Donald Trump does deserves an article
Obscurity ≠ Lack of notability
Offline sources
One hundred words
One sentence does not an article make
Other stuff exists
Overreliance upon Google
Perennial websites
Pokémon test
Read the source
Reducing consensus to an algorithm
Run-of-the-mill
Solutions are mixtures and nothing else
Subjective importance
Third-party sources
Trivial mentions
Video links
Vanispamcruftisement
What BLP1E is not
What is and is not routine coverage
What notability is not
What to include
Wikipedia is not Crunchbase
Wikipedia is not here to tell the world about your noble cause
Wikipedia is not the place to post your résumé
Humorous essays
Adminitis
Akin's Laws of Article Writing
Alternatives to edit warring
ANI flu
Anti-Wikipedian
Anti-Wikipedianism
Articlecountitis
Asshole John rule
Assume bad faith
Assume faith
Assume good wraith
Assume stupidity
Assume that everyone's assuming good faith, assuming that you are assuming good faith
Avoid using preview button
Avoid using wikilinks
Bad Jokes and Other Deleted Nonsense
Barnstaritis
Before they were notable
BOLD, revert, revert, revert
Boston Tea Party
Butterfly effect
CaPiTaLiZaTiOn MuCh?
Complete bollocks
Counting forks
Counting juntas
Crap
Don't stuff beans up your nose
Don't-give-a-fuckism
Don't abbreviate "Wikipedia" as "Wiki"!
Don't delete the main page
Editcountitis
Edits Per Day
Editsummarisis
Editing Under the Influence
Embrace Stop Signs
Emerson
Fart
Five Fs of Wikipedia
Seven Ages of Editor, by Will E. Spear-Shake
Go ahead, vandalize
How many Wikipedians does it take to change a lightbulb?
How to get away with UPE
How to put up a straight pole by pushing it at an angle
How to vandalize correctly
How to win a citation war
Ignore all essays
Ignore every single rule
Is that even an essay?
Mess with the templates
My local pond
Newcomers are delicious, so go ahead and bite them
Legal vandalism
List of jokes about Wikipedia
LTTAUTMAOK
No climbing the Reichstag dressed as Spider-Man
No one cares about your garage band
No one really cares
No, really
No sorcery threats
Notability is not eternal
Oops Defense
Play the game
Please be a giant dick, so we can ban you
Please bite the newbies
Please do not murder the newcomers
Pledge of Tranquility
R-e-s-p-e-c-t
Requests for medication
Requirements for adminship
Rouge admin
Rouge editor
Sarcasm is really helpful
Sausages for tasting
The Night Before Wikimas
The first rule of Wikipedia
The Five Pillars of Untruth
Things that should not be surprising
The WikiBible
Watchlistitis
Wikipedia is an MMORPG
WTF? OMG! TMD TLA. ARG!
What Wikipedia is not/Outtakes
Why not create an account?
Yes legal threats
You don't have to be mad to work here, but
You should not write meaningless lists
About essays
About essays
Essay guide
Value of essays
Difference between policies, guidelines and essays
Don't cite essays as if they were policy
Avoid writing redundant essays
Finding an essay
Quote your own essay
Policies and guidelines
About policies and guidelines
Policies
Guidelines
How to contribute to Wikipedia guidance
Policy writing is hard
v
t
e
Wikipedia technical help
Get personal technical help at the Teahouse, help desk, village pump (technical), talk pages or IRC.