Template gadgets
Appearance
Template gadgets are gadgets that load when a certain template is present in a page, usually to implement or extend the functionality of the template. Template gadgets allow features that are otherwise impossible in templates, such as API calls, restricted HTML elements, Codex interfaces, and much more.
Existing template gadgets
[edit]Global
[edit]Template gadgets in this list are also global gadgets, designed and ready to be used in any wiki (Wikimedia or not) and in any language.
- Template:OWID - Embed interactive charts from Our World in Data
- Template:Conway's Game of Life - Make an interactive instance of Conway's Game of Life
- Template:Langton's ant - Make an interactive instance of Langton's ant
- Template:Download PDF - Print or download a specified set of pages
- Template:Search - Search the wiki and display the results in a wiki page
- Template:Excerpt tree - Navigate excerpt trees
- Template:ImageStackPopup - Make a pop-up media gallery viewer suitable for medical images
Local
[edit]Template gadgets in this list are not fully globalized yet.
- v:Template:Wikidebate - Adds tools for wikidebates
- es:Template:Firmar - Easily sign in votes, polls and wikiprojects
- es:Template:Formulario - Make forms that inject content into other pages
- es:Template:Checkbox - Make checkboxes that preserve the state
- es:Template:Wikiproyecto - Add functionality to WikiProjects
- es:Template:Hola - Simple demo of a template gadget
Create a new template gadget
[edit]If you create a new template gadget, please add it to the appropriate list above so that others may find it, use it and improve it!
General method
[edit]To create a template gadget:
- Create a template or Lua module that inserts the basic HTML markup you will need, and categorizes pages in a category created just for this purpose
- Develop the necessary JavaScript in your common.js
- When ready, ask your community to review and promote your JavaScript to the MediaWiki namespace, and define a gadget that loads said JavaScript for pages in your special category
Best practices
[edit]- Design your template gadget so that it's usable by other wikis (example). Host it at MediaWiki.org (example) and have other wikis load it from there (example).
- Separation of concerns can be achieved by moving HTML to the template (example) and CSS to a separate stylesheet (example) that can then be loaded from the template script itself (example).
- Encapsulate your code within a class to keep it tidy and avoid unnecessary naming conflicts (example).
Limitations
[edit]- Template gadgets will not be loaded in AJAX-based previews like Live preview, real-time preview, VisualEditor, mobile app previews, etc.
- Template gadgets will not work with 3rd party clients (including the official Wikipedia Android and iOS app) that do not load wiki scripts (typically for security reasons). For this reason make sure your gadget progressively degrades to something functional or at least an error message that says "This is not supported by your client".
- Template gadgets can be broken by vandalism (e.g. removal of categories from a page).
See also
[edit]- TemplateScripts - Predecesor of template gadgets