Template:Evalx/doc
This is a documentation subpage for Template:Evalx It may contain usage information, categories and other content that is not part of the original template page. |
This template is used on 99,000+ pages and changes may be widely noticed. Test changes in the template's /sandbox or /testcases subpages, or in your own user subpage. Consider discussing changes on the talk page before implementing them. |
Usage
editThis template evaluates an expression sequence using Module:Wikilisp. Pass the expression sequence as the first unnamed template parameter; all parameters to the template are also passed to the the module. For example,
{{evalx|(get-substring (get-arg 2) 2 3)|abcd}}
would expand to
- bc
Here's a nontrivial example, made to work in concert with dialog verb edit. It modifies the entire content of a wiki page (provided through template parameter SUBJECT-CONTENT
) to submit the article for review on Wikinews, by removing calls to templates {{develop}} and {{tasks}} and adding a call at the top of the page to template {{review}}.
{{evalx|(define s (get-arg 2)) (define t (filter (parse s) call? (\x (member? (ucfirst (trim (get-substring s (nth (get-parts x) 1)))) (list "Dialog/submit" "Develop" "Developing" "Development" "Draft" "Tasks"))))) (set-substring s (+ (list (list 1 0)) t) (+ (list "{{(*}}{{(*}}review{{*)}}{{*)}}") (map (\x "") t))) |{{{SUBJECT-CONTENT|}}}}}
A different module, to use instead of Module:Wikilisp, may be specified by non-blank template parameter test-eval
.
Internals
editWhen Module:Wikilisp is #invoke
d directly, rather than through an intermediary template such as {{evalx}}, the module point of entry is Lua function rep
, and the invocation parameters are accessible through Wikilisp functions get-arg
and get-arg-expr
. However, the intermediary template cannot explicitly pass its arbitrary template parameters to the invocation since it doesn't know their names in advance. To compensate, an alternative point of entry is provided through Lua function trep
, that feeds get-arg
and get-arg-expr
the parameters to the intermediary template instead of the parameters to #invoke
.
See also
edit- Module:Wikilisp for documentation of the expression language.