Kannada Language Workshop/Resources-Templates
Introduction
editTemplates in Wikipedia are powerful tools that allow editors to reuse standardized text, information, or code across multiple pages. This guide provides an overview of how to create and use templates using transclusion, substitution, and more advanced features.
1. Understanding Templates
editTemplates are reusable pieces of code or text that can be embedded on any Wikipedia page. When you add a template, it automatically transcludes content from the template page into your article, making edits easier and ensuring consistency.
Types of Template Usage
editTemplates are primarily used in two ways:
- Transclusion: Embeds the contents of one page (the template) directly into another page.
- Substitution: Inserts the template content directly into the page source code, making it part of the page itself.
2. Creating a Basic Template
editTo create a basic template, follow these steps:
1. Navigate to the Template namespace (e.g., `Template:Example`). 2. On the template page, create your content using wikitext. A template can include text, links, or other templates.
Example:
{{Example}}
This creates a simple placeholder template.
3. Using Templates
edit3.1. Transclusion of Templates
editOnce the template page is created, you can embed it into other articles by using transclusion. Transclusion reflects any changes made to the template in real time.
To transclude a template:
{{Template:Example}}
This will embed the content of the `Template:Example` page.
3.2. Substitution of Templates
editSubstitution copies the content of the template into the page source code.
To substitute a template, use the `subst` keyword:
{{subst:Template:Example}}
This replaces the template call with the template’s content in the source.
4. Template Parameters
editTemplates can use parameters to accept custom inputs when used. These are defined and passed during the template call.
Example:
{{Template:Infobox
|name = Example Name
|description = Example description
|date = 2025
}}
5. Advanced Template Features
edit5.1. Parser Functions
editParser functions allow conditional logic, mathematical operations, and string manipulation in templates.
Example:
{{#if:{{{name|}}}|Welcome, {{{name}}}|Hello, guest!}}
This displays a personalized greeting if the `name` parameter is provided.
5.2. Using Expression Parser Functions
editExpression parser functions enable calculations and logical comparisons in templates.
Example:
{{#expr: 10 + 2}}
This outputs:
12
6. Magic Words
editMagic words are special codes that perform various functions, such as inserting dynamic content, controlling page behavior, or formatting outputs.
Common Types of Magic Words
editMagic words are broadly categorized into:
- Variables: Insert dynamic content like the page name or current date.
- Behavior switches: Modify page behaviors.
- Parser functions: Add functionality like conditional statements and math operations.
Magic Words Table
editThe following table shows commonly used magic words with their actual outputs:
Magic Word | Code | Result |
---|---|---|
Current Page Name | {{PAGENAME}}
|
Kannada Language Workshop/Resources-Templates |
Current Date and Time | {{CURRENTTIME}}
|
02:28 |
Current Year | {{CURRENTYEAR}}
|
2025 |
User Language | {{CONTENTLANGUAGE}}
|
en |
Number of Articles | {{NUMBEROFARTICLES}}
|
153,218 |
Default Separator | {{!}}
|
|
Page ID | {{PAGEID}}
|
12959895 |
Formatted Date | {{#time:d M Y|2025-01-01}}
|
01 Jan 2025 |
Using Magic Words in Templates
editMagic words can dynamically adjust template output based on context.
Example:
The page "{{PAGENAME}}" was last updated in {{CURRENTYEAR}}.
Output: > The page "Help:Example" was last updated in 2025.
7. Best Practices
edit7.1. Keep Templates Simple
editAvoid overly complex templates. Break them into smaller, reusable components when necessary.
7.2. Document Templates Properly
editProvide clear documentation on the template’s purpose and usage to assist other editors.
7.3. Test Templates Before Using
editTest templates in sandbox pages or the template’s dedicated sandbox area.
Conclusion
editTemplates improve efficiency, consistency, and readability on Wikipedia. Whether creating simple templates or advanced ones using parser functions and magic words, understanding their proper use can greatly enhance your editing experience.