Help:Infoboxes
Approach
For each dataset we create:
- a form that is responsible for the data collection and its primary validation;
- a template that passes the collected data to the Scribunto module for further processing;
- a module that:
- sets the correspondence between form fields and semantic properties
- provides a schema of the infobox
- optionally defines the main category and footer for pages
- passes data to helper modules that build an infobox
For easier tracking I use the same name for the form, template and module. See here.
Properties Plan
Returns a table of data containing the form field names on the left and the corresponding semantic property name on the right, e.g.:
-- Left -- Right
['Image'] = {'Image', 'file' },
['Has status'] = {'Has status' },
['Plays game'] = {'Plays game', ',' },
The second optional argument for the subtable on the right is a delimiter, which indicates that the property can hold multiple values. It must match the delimiter defined in the form field configuration for lists. By default, PageForms uses a comma as the delimiter, but this can be redefined in cases where property values themselves may contain commas.
For values that are file names we should set file as argument to ensure its special processing.
Infobox Schema
The schema defines logical blocks for the infobox, like this:
local sectionMap = {
['Cover image'] = {
heading = '',
template = 'Infobox/Cover',
order = '1',
rows = {
'Image'
}
},
['Player Info'] = {
heading = 'Player Info',
template = 'Infobox/Player Info',
order = '2',
rows = {
'Has status',
'Plays game',
'Plays mod',
'Has favorite mod'
}
},
['Clans'] = {
heading = 'Communities',
template = 'Infobox/Clans',
order = '3',
rows = {
'Communities'
}
},
['Wiki'] = {
heading = 'Wiki',
template = 'Infobox/Wiki',
order = '4',
rows = {
'Is guardian for',
'Is mentor for',
'Contact links'
}
}
}
- a heading for the section
- an order that determines the section’s position in the infobox
- a subset of rows, containing the field names to be displayed in the section
- a template responsible for rendering the individual rows in the section
This way, one can easily understand and manage the infobox structure at a high level, share, re-use and replace data rendering templates.
Rendering templates
The purpose of the rendering templates is to allow for fine tuning the infobox row output. A typical pattern that applies to the regular field looks like this:
{{#if: {{{Game|}}}
|{{Infobox/Generic
|Game
|{{{Game|}}}
|multiple=1
|sep=,
|links=1
|form=Game
|indicator=green
}}
}}
It checks, that the value exists and returns nothing if it doesn't. We use Template:Infobox/Generic to render a regular infobox row. Apart the first two unnamed parameters that set the row label and value, it accepts the following optional modifiers:
- multiple — set to 1 if the value must be split in fragments.
- sep — required if a custom delimiter is used. Otherwise, it defaults to a comma and auto-enabled if multiple modifier was set.
- links — set to 1 if the value must be rendered as a link.
- form — set the name of the form the link should use if a required page doesn't exist yet, for easy page creation. It requires links to be enabled.
- indicator — set into any valid color name, variable or hex to display a LED indicator.
The content of subobjects is usually rendered by the subobject modules themselves, so we just let them pass through using Template:Infobox/Subobject, like this:
{{#if: {{{Contact links|}}}
|{{Infobox/Subobject
|Contact
|{{{Contact links|}}}
}}
}}
As you see, it uses two unnamed parameters that set the row label and value. The latter will be replaced with the rendered subobject instances in the infobox.
To identify the infobox formatter templates easily, I put them all as subpages to Template:Infobox:
Workflow
When creating a new dataset, one is advised to:
- Plan properties, set their data types, property descriptions, and allowed values (if applicable).
- Create a form using the existing forms as a model.
- Create a template using the existing main templates as a model.
- Create a module, adjusting the properties plan, the infobox schema, the category and the footer template (if used).
- Create the missing rendering templates, fine tune or customize the output format.
