FANDOM


PreloadTemplates allows users to insert a premade syntax from a list of selectable templates directly within the source editor.

Installation

See also: Help:Including additional CSS and JS, Help:Advanced CSS and JS
  • For site-wide use, an administrator can add the line below to the wiki's MediaWiki:ImportJS page. Note that JavaScript must be enabled on the wiki.
dev:PreloadTemplates.js

Configuration

The script can be used as it is, but it does also support these customizable variables that can be added before the import on Common.js. Common.js will run before MediaWiki:ImportJS.

Using configuration options with Fandom Open Source Library scripts
The instructions on this page describe how to use configuration options with a script. Here on the Fandom Open Source Library, many scripts provide optional configuration settings as a mean to alter or enhance the default behavior of the script. When installing configuration options in your JavaScript file, please note that they need to go above the import statement in order to work — unless the directions say otherwise. In case MediaWiki:ImportJS is used to load the scripts, it will be executed last.
Configuration options load too late, don't work
Proper placement of configuration options
// 1. AjaxRC import statement
importScriptPage('AjaxRC/code.js','dev');
 
// 2. AjaxRC configuration option
var ajaxRefresh = 30000;
// 1. AjaxRC configuration option
var ajaxRefresh = 30000;
 
// 2. AjaxRC import statement
importScriptPage('AjaxRC/code.js','dev');
Variable Description Default value Type
preloadTemplates_list Set the page name (namespace included) with the list of templates to be preloaded. MediaWiki:Custom-PreloadTemplates string

Example:

preloadTemplates_list = MediaWiki:Custom-PreloadTemplatesList;
preloadTemplates_subpage Set the name of the subpage that every template will use to store the premade syntax. preload string

Example:

preloadTemplates_subpage = syntax;

Use

To use the tool, you have to create the required pages:

  • MediaWiki:Custom-PreloadTemplates (or whatever you set as your template list).
    • You will add here the list of the templates you want to preload from the editor. Everything in an wikitext bulleted list (the list made by *) will be treated as a template name. Everything else will be treated as normal text.
  • For each template you listed, you have to create the subpage preload (or whatever you set as your subpage).
    • Here you will add the text that you want to be preloaded as it is when the template is selected.

Both kind of pages support the use of <noinclude></noinclude> and <includeonly></includeonly> tags.

Example

Using the default configuration and taking a look at the example shown in the image we have:

  • On MediaWiki:Custom-PreloadTemplates the code
Generic templates:
* Template 1
* Template 2
* Template 3

Other templates:
* Template 4
* Template 5
* Template 6

With this code, clicking on any of the template listed there will add the text stored on the subpage, for example Template:Template 1/preload.

  • On /preload if we use
<includeonly>
{{Template 1
| parameter A   = 
| parameter B   = 
| parameter C   = 
}}</includeonly>
<noinclude>
[[Category:Preload pages]]
</noinclude>

When the template will be preloaded only the following code will be added to the editor:

{{Template 1
| parameter A   = 
| parameter B   = 
| parameter C   = 
}}

Preload tags

If you want to preload noinclude/includeonly tags (for example with a category), you can do so by using a trick like this:

<no<includeonly></includeonly>include>
[[Category:Name]]
</no<includeonly></includeonly>include></includeonly>

which will results in

<noinclude>
[[Category:Name]]
</noinclude>

once preloaded.

Localization

To add other languages, provide the translations for these strings:

            // English
            en: {
                preload: 'Preload template:',
                choose: '(choose)',
                help: 'Select a template to insert its preloaded syntax at the current position ',
                devWiki: 'Check the documentation on Dev Wiki',
                error: 'No valid syntax found at $1 or page is missing.'
            },

Note: if you need to use the character ' escape it like this \'. Don't change/remove $1.

Changelog

Date Notes Updated by
October 7th, 2016 Created leviathan 89
October 9th, 2016 Added other languages, better skins support leviathan 89
October 15th, 2016 Added other languages leviathan 89

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.