Help:Parser function basics

From Ballotpedia
Jump to: navigation, search

Parser functions are wiki tools that are designed to allow you to create logic statements on the wiki that will alter the results of a page based upon certain factors or arguments indicated in the parser function. A full list of parser functions available on our wiki can be found here. Parser functions all begin with “{{#NAME:” where NAME is the function being called. Parser functions end with “}}” much like a template. The most common parser functions in use on the LBI wikis include the "expression" parser "if" parser, the "If equals" parser, the "switch" parser and the "date and time" parser. This page will go over parser basics. For specific instructions on each of these parsers, please see the specific help page.

Common parser uses

Advanced templates

See also:Help:Basic template transclusion

Parsers are most commonly used within advanced templates involving individual parameters. Often on wiki’s you will need to set up templates which are common amongst pages but which will contain specific pieces of information that are different, i.e. infoboxes. This can be done using three curly brackets, {{{TEXT}}}. For easy use, I’ll call these “parameters” and the text used to summon a template, a “template call”. It is important to note that three brackets ({{{TEXT}}}) create a parameter within a template, while two curly brackets ({{Text}}) are used to summon a template onto a page or to begin a parser function. You can then attach parsers to these parameters that allow you to alter the template based on the parameter involved.

Review of Parameters:

The template code reads:
This is my {{{Parameter}}} test. Hello {{{Target}}}.

The Template call reads:
{{Template name|Parameter=communication|Target=world}}

The template on page reads:
This is my communication test. Hello world.

Some additional notes on parameters:

  • Parameters are included with three curly brackets ({{{) on a template page: i.e. {{{Parameter}}}
  • To automatically define a parameter in the event that it is undefined on a page, use a pipe (|) after your parameter and define it: i.e. Definition
  • Parameters can be used within Templates that hold DPL's to change the dpl call for the page you are including it on.
  • Fixed Wiki Variables can be used as parameters to incorporate specific meta-information on a template, like the page name or time stamp. This will render the page name of the page on which you are including the template.


Parsers can also be used with DPL's to manipulate the information summoned in a DPL call. However, a perser included in the DPL call must be incorporated via a third template call within the "secseparators" section of the DPL code. More on this can be found in our help pages at Help:DPL advanced formatting, section separators and Help:DPL advanced formatting, tables.

Common Parsers

Expression parser

See also: Help:Expression and If expression parser
  • {{#expr: 5 + 2}} =This is a basic math parser and can be used to add, substract, multiply divide or round numbers entered on the wiki.

If parser

See also: Help:If parser
  • {{#if:X|Y|Z}} = If X is defined, then display Y. If not, display Z. A parameter is defined if your template call includes {{Template Name|X=Some text}} .

If Equals parser

See also: Help:IfEq parser
  • {{#ifeq:A|B|X|Y}} = If A is defined as B, then display X. If not, display Y. A parameter is defined specifically if your template call includes {{Template Name|A=B}} .

Switch parser

See also: Help:Switch parser
  • {{#switch:A|B=X|C=Y|D=Z}} = If A is defined as B, then display X. If A is defined as C, then display Y. If A is defined as D, then display Z. A parameter is defined specifically if your template call includes {{Template Name|A=B}} .

Advanced parser notes

  • Parsers may be nested inside each other. However, be sure to close your brackets accordingly.