Template:LayoutTemplateArgs

From "PTTLink Wiki"
Revision as of 15:31, 24 January 2022 by Kg7qin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:LayoutTemplateArgs/doc.

Helper template for passing parameters to templates using the Ajax in-line template translation feature

Usage

{{LayoutTemplateArgs |args= |template= }}

English: The value of the "args" parameter should be a list of template parameters separated by whitespace (not by "|"), with each parameter URL-encoded.

Example:
{{LayoutTemplateArgs|template=<Template name>|args=
{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: foo={{{foo|}}} }}
{{urlencode: bar={{{bar|}}} }}
}}

Template parameters

<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.


Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. <nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw <templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.

Discussion
There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.


Wikipedia's help about TemplateDataCommons-specific information

Helper template for passing parameters to templates using the Ajax in-line template translation feature

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
parametersargs

List of template parameters, URL-encoded and separated by whitespace (see above)

Contentrequired
template nametemplate

The name of the template for which these parameters are meant for, without the "Template:" prefix

Templaterequired

Additional information

The template is intended to be used in the following namespaces: the Template namespace

The template is intended to be used by the following user groups: all users

Placement:

English: This template should be used on the "/layout" subpage of an autotranslated template, within the element with the "layouttemplate" class, preferably before any actual content.

Relies on:

⧼Seealso⧽

Localization

This template is not intended to be localized.

Using this template

These instructions assume that you're starting with a standard {{Autotranslate}}-style template (whether it actually uses {{Autotranslate}} or not) with the usual "/layout", "/lang" subpages and one or more "/xx" ISO 639 language code subpages.

Step 0: First, to enable the in-line translation feature for the template, the outermost containing element for each translated version must be given the "layouttemplate" class if it doesn't already have it. What this means in practice is that you should edit the "/layout" subpage of the template and add class="layouttemplate" to the first <div> tag or table there. (If it already has a class attribute, append "layouttemplate" to the value; e.g. replace class="someclass otherclass" with class="someclass otherclass layouttemplate". If the classes are specified via yet another template, edit that template instead.) If there is no single <div> or table that would enclose the entire content, you can add one: just wrap the whole thing in <div class="layouttemplate">...</div>. Finally, make sure there are no other elements with the "layouttemplate" class.

If the in-line translation feature already works for your template, you can skip the previous paragraph and start here. Also, if the template takes no parameters, you don't need to do anything more. If it does, do the following:

Step 1: Make sure all the parameters given to the template are passed to the "/layout" subpage. If not, you first need to edit all the translated versions of the template so that this is the case. For example, if your template takes three numbered parameters and the named parameter "foo", insert the following lines into each of the translated subpages:

|1={{{1|}}}
|2={{{2|}}}
|3={{{3|}}}
|foo={{{foo|}}}

Step 2: Edit the "/layout" subpage and insert {{LayoutTemplateArgs}} inside the element with the "layouttemplate" class, as early as possible. If the element is a div, you can just put it immediately after the <div> tag; if it's a table, put it at the beginning of the the first table cell. The value of the "args" parameter should contain all the parameters you want to have passed to the translated versions during in-line replacement, individually URL-encoded and separated by whitespace (i.e. spaces or linebreaks; not pipes as in normal template calls). For example, if your template takes the same parameters as above, and is named Template:FooBar, the code you should add to Template:FooBar/layout would be:

{{LayoutTemplateArgs|template=<Template name>|args=
{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: 3={{{3|}}} }}
{{urlencode: foo={{{foo|}}} }}
}}

Now test your template to see that it works as expected. If not, fix it or ask for help.

Known issues

There are a couple of known bugs in this template and in the associated Ajax translation script, including:

Parameters containing <nowiki>, <pre>, <poem>, <ref>, <gallery>, etc. tags turn into gibberish cause the in-line replacement not to work.

This is a known bug in the MediaWiki {{urlencode:}} parser function: when given input containing "parser extension tags", those tags and their content get replaced by internal "strip markers" which look something like "&#x7F;UNIQ77ef13a860481bc0-nowiki-00000010-QINU&#x7F;". Unfortunately, there's no way for the Ajax translation script to work out what the content replaced by such strip markers might've originally been. The current implementation reverts to opening the translated template on a new page if it detects any strip markers in the parameters.

Very long parameter values cause the in-line replacement not to work.

The in-line replacement code uses a MediaWiki API query to load the translated version of the template. For simplicity and efficiency, the current implementation uses HTTP GET requests to access the API, which means that the name of the template and all the parameters are included in the query URL. If this URL gets longer than about 4 kilobytes, the servers will reject it as excessively long. The current code simply refuses to generate such long URLs, and reverts to opening the translated template on a new page instead.

Autotranslated templates included in parameters will be shown in the user's default language even after in-line replacement.

This happens simply because those templates get parsed and expanded before the Ajax translation code ever sees them. Note that passing complex templates in parameters is also likely to trigger the previous bug as well.