Pergunta

So I have a MediaWiki template which I use within a table to represent one column. The code looks like this and works as I want it.

<includeonly>{{#if:{{{name|}}}|''{{{name}}}: ''|}}{{#if:{{{food|}}}|+{{Food|{{{food|}}}}}|}} {{#if:{{{condition|}}}|{{{condition|}}}|}}</includeonly>

When I use it with the input

{{Symbiosis|name=Groove|food=10|condition=if next to [[Apple Tree]], [[Dandelion]] or [[Straberry]]}}

I get the folling result which is as desired.

correct output

However now I want to extend this template and move the part with the food definition in another template because I need it elsewhere again. So I make a new ResourceList template which basically does the same as before.

<includeonly>{{#if:{{{food|}}}|+{{Food|{{{food|}}}}}|}}<includeonly>

and include it in my Symbiosis template to look like this.

<includeonly>{{#if:{{{name|}}}|''{{{name}}}: ''|}}{{ResourceList|food={{{food}}}}} {{#if:{{{condition|}}}|{{{condition|}}}|}}</includeonly>

But when I now use the same input as above I get a line break in my table to look like this. wrong output

Why is this? There are no spaces or linkebreaks in the template definitions. I don't really understand how MediaWiki handles all this, it is quite confusing and somewhat unintuitivive. All this whitespace and line break behavious is driving me nuts... Is there a way to tell MediaWiki that it might ignore all whitespaces and linebreaks within my template definition expect the ones I explecitly want to have?

Foi útil?

Solução

I can't reproduce your error.

I input all of the code from your second example exactly as written and it turned out like your first example. I tried it by itself and then I tried replicating your table based on the screenshot (see below), and in both cases no errant line break occurred.

{| class="wikitable sortable"
|- 
! width="33%" | Column A
! width="34%" | Column B
! width="33%" | Column C
|- 
| {{loremipsum}}
| {{Symbiosis|name=Groove|food=10|condition=if next to [[Apple Tree]], [[Dandelion]] or [[Straberry]]}}
| {{loremipsum}}
|}

Are you using a different css class in your table? Because sometimes that can cause unexpected wrapping or paragraph problems.

Outras dicas

This can happen when multiple templates with no output are included in sequence (not sure if that's the problem here).

Try adding <nowiki/> right before the end of each of the template (before any </includeonly>)

You can't rely on using the pipe character, |, in templates. Instead you should create a new template specifically for the pipe character. This is what Wikipedia does. This is simpler than it sounds. Simply:

  1. Create a new template called ! (so the page name will be Template:!).
  2. The page contents only need to be | (yes, just the pipe character).
  3. Use it by adding {{!}} to any template where you currently use the pipe character (ie replace | with {{!}})

See Template:! on Wikipedia for more information.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top