Contents
Card Macro
Description
This macro allows you to use parametrized includes in pages (similar to the templates used in MediaWiki).
Download
http://dev.axel.pp.ru/moinmoin/card-macro/1.5/Card.py
You may use Darcs to access the development repository (code for MoinMoin 1.5 and 1.3 respectively):
http://dev.axel.pp.ru/moinmoin/card-macro/1.5/ (view Darcs log)
http://dev.axel.pp.ru/moinmoin/card-macro/1.3/ (view Darcs log)
A version for Moin 1.9 is attached to the page. -- UeliSchläpfer, 2011-06-19
Syntax description
First we define a template page with special variables, for example name it CardExamplePage (prefix 'Card' is mandatory for card-templates):
#acl All:read,write,revert # Sample template for Card macro Hello, ${ARG0}! Hello, ${ARG1}!
Then you may insert a macro call like
[[Card(ExamplePage MoinMoin, world)]]
In the resulting page you get:
Hello, MoinMoin! Hello, world!
You may use positional arguments in the template, they are named ${ARG0}, ${ARG1} and so on. You may also use named variables like ${myvar}. There is one special variable - ${CALLER} (TODO: probably need to change name to CALLER_PAGE), this variable contains the name of page from which you called this macro.
An Example Page with macro definition:
# This is page CardExample with macro definition This macro called from ${CALLER}
Page with macro call:
# This is page SamplePage [[Card(Example)]] ...other text
Result:
This macro called from SamplePage ...other text
In the current version of this macro there are no default values for arguments.
Multiple arguments are by default separated with a ',' (this behaviour can be changed, if you define in wikiconfig.py the parameter cardmacro_separator (for example cardmacro_separator = "|"). Spaces after separators are ignored. Look at an example:
[[Card(Sample arg1,this is multiword argument 2, arg3)]]
Real life examples
Stub for draft pages
Template CardDraft:
||<: tableclass="card" bgcolor="#EEEEFF"> attachment:Blank_template.gif ||<: bgcolor="#EEEEFF"> This is draft page, help us with it: [[PageAction(${CALLER}, edit)]] ||
Usage: Card(Draft)
This template used the auxiliary macro PageAction - it is a modified version of an Action macro from MoinMoin: PageAction.py
Screenshot from my wiki (text in Russian):
Link to comments page
Template CardComments:
== $ARG0 == ||<( bgcolor="#FFFF99">''Discuss it:'' '''[[PageAction(${CALLER}/Comments, edit)]]'''|| ||<( bgcolor="#EEEEEE"> [[Include(${CALLER}/Comments)]] ||
Usage: [[Card(Comments link header)]]
Example screenshot for: [[Card(Comments Add you comment below)]]
Sites using this macro
English is not my native language, please correct errors in this text. -- AlexanderGrafov 2006-04-14 22:28:48
Spruced up the grammar for you. Nice macro by the way. -- PiMasta 2007-03-08
Discussion
Caveat: When using this macro, I created a line CategoryBleh within the text that is included via CardBleh, and then put this onto a page via the macro. However, if I then list members of the category I don't see that page listed. If I manually at CategoryBleh to the page without using the CardMacro then it is listed fine. It seems like the Category listing looks at the "raw" page when deciding what's in it's Category, rather than the finished article with the Card included. Is this a bug?
I would prefer , and not | as separator for arguments of a parameterlist. Because all other macros and parsers do use ,. If each parser/macro needs always an other separotor it makes explaining and using much more complicated. If you want to keep | for your pages add , as new default. -- ReimarBauer 2006-04-15 05:49:32
You're right. I changed default separator to comma and added optional parameter to wiki config for change separator to pipe of something else. Users of old version of the CardMacro need to rewrite their calls or define cardmacro='|' in wikiconfig. -- AlexanderGrafov 2006-04-19 17:07:58
A minor tweak for the separator might be to use " ," (note the space before the comma). Reason for this is that if you have a 1 argument template, you can't use a comma as normal [[Card(MyTemplate Blah blah, however blah blah)]] will have 2 arguments, but it should be 1. [[Card(MyTemplate Blah blah , however blah blah)]] makes it obvious they should be 2 different arguments. Works fine on my wiki, just make sure you have a space before your commas when specifying arguments. Just a thought. -- PiMasta 2007-03-08 20:03:58
May be we should think about always using "some text, some strings" for strings as we did in python or other languages for parameters which are strings too. But that is a big change for all using or developing macros or parsers. Later on after the class ParameterParser of wikiutil is finished it will help us to interpret submitted parameters. So the input of parameters into a plugin could be standardized internally. -- ReimarBauer 2007-06-27 20:07:42
Sorry, but i can't download your Macro. I have a timeout error from my browser. -- penaz
The download link for any of the versions does not work. Does anyone have this Macro? Please update download link.