Difference between revisions of "Template:Escape/doc"

From blackwiki
Jump to navigation Jump to search
imported>NisJørgensen
(Someone wrote this documentation without actually describing what the template does, only in which cases it is used.)
imported>Vanisaac
m (→‎Examples: clean up per WP:CAT#T and WP:AWBREQ add template:Sandbox other)
Line 52: Line 52:
 
}}
 
}}
  
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
+
<includeonly>{{Sandbox other||
 
<!-- Categories below this line, please; interwikis at Wikidata -->
 
<!-- Categories below this line, please; interwikis at Wikidata -->
 
[[Category:Wikipedia_utility_templates]]
 
[[Category:Wikipedia_utility_templates]]
 
}}</includeonly>
 
}}</includeonly>

Revision as of 01:34, 25 April 2020

Usage

While primarily intended for use by other Lua modules, it can provide an alternative to multiple <nowiki>...</nowiki> tags when part of the desired output should be executed.

For example, Template:T normally requires the demonstrated template to be wrapped in <nowiki>...</nowiki>. However, you may want part of the value to be shown in the 'pre' tag to be processed before it reaches Template:T, such as in the example below where the result of {{#invoke:Escape/testcases|test_string2}} is shown inside the <pre>...</pre> tags.

Code Result
{{demo
|<!--not escaped: -->{{escape | mode = kill 
  | char=; 
  | {*{#invoke:Escape ; main ; mode {{=}} kill ;
<!--unescaped:-->{{#invoke:Escape/testcases|test_string2}}<br>; { }*} 
  | * 
  | {{!}} }}
}}
{{#invoke:Escape | main | mode = kill |
test { test {\{ test, \test, \{,test\ \ \ {\
| { }}

test test { test, test, {,test

Note how the * character, used to break up the {{ to prevent execution, is removed and how the ; character is replaced by |.

Non-execution

After removal of the escape chars, the returned text is inert; i.e. not executed even without <pre>...</pre>. (The above example is executed only because Template:T forces execution.)

For example, setting |mode=kill with \{\{done\}\} as the first parameter and nothing else will simply cause the default escape character \ to be removed:

{{done}}

Examples

Module talk:Escape/testcases