String functions in MediaWiki template?

One of the most interesting “programming languages” I've recently stuck with is the MediaWiki templates. You can make an amazing amount of material with the limited syntax that they give you, but lately I have run into a problem that disgusts me: using string functions in template arguments. What I would like to do (somewhat simplified):

{{myTemp|a=1,2,3,4}} 

then write a template that can do some kind of magic, for example

 You told me _a_ starts with {{#split:{{{a}}}, ",", 0}} 

Currently I can do this with inline javascript, grab the regex and document.write, but a) it is huge, b) it is hacked, and c) it will break badly if someone disables javascript. (Note that “split” is just an example, match, capture-regular expression match, etc. It would be even better)

I understand that the correct solution is for the caller to invoke the template with separate arguments, but for various reasons that would be difficult in my particular case. If this is simply not possible, I think the answer is, but if there is some way to get the templates to manipulate the string at the back end, that would be great.

+6
string templates mediawiki wiki
source share
2 answers

Concatenation is simple. To assign x = y concat z

 {{#vardefine:x|{{{y}}}{{{z}}}}} 

And to add Mark's answer, there is also RegexParserFunctions

Ceterum censeo: MediaWiki will never be hacks.

+6
source share

You can do this with extensions, for example. StringFunctions But see also ParserFunctions and ParserFunctions / Extended , (you will find many more examples in Category: Parser Function Extensions .)

Great review of Help: Extension: ParserFunctions .

+2
source share

All Articles