سؤال

How do I ignore whitespace on a wiki template?

So for example, I create a template called Hello. Inside that, I put {{{text}}}.
So now when I put {{Hello |text=Hi Bye}} on a page, and save it, the page says. "Hi Bye" (of course).

I want it to display "HiBye", not "Hi Bye". What do I put in the template to do that?

هل كانت مفيدة؟

المحلول

To remove characters inside the value in a template (whitespace or other), you have to search and replace. You can install the extensions ParserFunctions, to get access to parser functions like replace, and then to something like this:

{{#replace:{{{text|}}}| |}}

If your MediaWiki is version 1.18 or newer (if it's not, you should upgrade anyway), ParserFunctions is already bundled with your installation. Then you just have to enable it, like this in LocalSettings.php:

require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
$wgPFEnableStringFunctions = true;

On a side note, whitespace characters in the beginning and end of a variable is always stripped, if using named parameters. In other words: {{Hello |text= Hi Bye }} is equal to {{Hello |text=Hi Bye}}. On the other hand, {{Hello | Hi Bye }} is not equal to {{Hello |Hi Bye}}. Advanced templates sometimes make clever use of this difference. The replace function will work in both cases, of course.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top