Jump to content

Kannada Language Workshop/Resources-Templates

From Meta, a Wikimedia project coordination wiki

Introduction

[edit]

Templates 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

[edit]

Templates 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

[edit]

Templates are primarily used in two ways:

  1. Transclusion: Embeds the contents of one page (the template) directly into another page.
  2. Substitution: Inserts the template content directly into the page source code, making it part of the page itself.

2. Creating a Basic Template

[edit]

To 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

[edit]

3.1. Transclusion of Templates

[edit]

Once 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

[edit]

Substitution 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

[edit]

Templates 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

[edit]

5.1. Parser Functions

[edit]

Parser 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

[edit]

Expression parser functions enable calculations and logical comparisons in templates.

Example:

{{#expr: 10 + 2}}

This outputs:

12

6. Magic Words

[edit]

Magic words are special codes that perform various functions, such as inserting dynamic content, controlling page behavior, or formatting outputs.

Common Types of Magic Words

[edit]

Magic words are broadly categorized into:

  1. Variables: Insert dynamic content like the page name or current date.
  2. Behavior switches: Modify page behaviors.
  3. Parser functions: Add functionality like conditional statements and math operations.

Magic Words Table

[edit]

The 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}}
22:56
Current Year
{{CURRENTYEAR}}
2025
User Language
{{CONTENTLANGUAGE}}
en
Number of Articles
{{NUMBEROFARTICLES}}
153,212
Default Separator
{{!}}
Page ID
{{PAGEID}}
12959895
Formatted Date
{{#time:d M Y|2025-01-01}}
01 Jan 2025

Using Magic Words in Templates

[edit]

Magic 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

[edit]

7.1. Keep Templates Simple

[edit]

Avoid overly complex templates. Break them into smaller, reusable components when necessary.

7.2. Document Templates Properly

[edit]

Provide clear documentation on the template’s purpose and usage to assist other editors.

7.3. Test Templates Before Using

[edit]

Test templates in sandbox pages or the template’s dedicated sandbox area.

Conclusion

[edit]

Templates 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.

References

[edit]