Jump to content

Module talk:DemoTemplate

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Doesn't preserve outer spacing

[edit]

See how it doesn't preserve outer spaces around " two inner spaces ". Is that the way we want it to behave? Or is it just the MediaWiki software?

{{#invoke:DemoTemplate|template usage|pattern= two inner spaces }}{{template usage|pattern=two inner spaces}}Testing two inner spaces on this page Thanks. — CpiralCpiral 08:43, 24 June 2015 (UTC)[reply]

All templates do that. Whitespace at the start and end is stripped in all named and explicitly numbered parameters, but not in unnamed ones:
  • "{{echo| abc }}" → " abc "
  • "{{echo|1= abc }}" → "abc"
  • "{{#invoke:DemoTemplate|echo| abc }}" → "{{1x| abc }} → abc "
  • "{{#invoke:DemoTemplate|echo|1= abc }}" → "{{1x|abc}} → abc"
Since whitespace is stripped before a parameter is passed into a module/template, nothing can be done within this module, but whitespace can be kept by adding <nowiki/> when using it:
  • "{{echo|1=<nowiki/> abc <nowiki/>}}" → " abc "
  • "{{#invoke:DemoTemplate|echo|1=<nowiki/> abc <nowiki/>}}" → "{{1x|'"`UNIQ--nowiki-0000000A-QINU`"' abc '"`UNIQ--nowiki-0000000B-QINU`"'}} → abc "
SiBr4 (talk) 15:28, 24 June 2015 (UTC)[reply]

Doesn't preserve order of parameters

[edit]

{{#invoke:DemoTemplate|Val|11|p=$|upl=acre}}{{Val|11|upl=acre|p=$}}$11/acreCpiralCpiral 23:16, 19 July 2015 (UTC)[reply]

@Cpiral: This is a result of standard behavior of Scribunto/Lua. Parameters are passed into a module as a Lua table, which does not preserve the order of named fields. When looping over named table fields, like this template does, they are therefore evaluated in arbitrary order. Nothing can be done in this module, short of adding a front-end parameter to explicitly specify the list of parameters and their order. SiBr4 (talk) 17:46, 26 July 2015 (UTC)[reply]