Jump to content

Help:RiskDisplay

From RiskiPedia

Help:RiskDisplay

The <riskdisplay> tag is the main engine for showing dynamic content on RiskiPedia. It calculates and displays the result of a risk model, reacting in real-time as a user changes their selections.

It can be used in three main ways:

  1. By itself, referencing a pre-defined <riskmodel>.
  2. By referencing a model, but overriding some of its parameters or content.
  3. As a "standalone" or "inline" model, with all calculations defined inside the tag.

RiskDisplays are put on pages with DropDown, RiskParameter, or RiskDataLookup elements to allow users to choose different variables that affect the risk calculation.

Syntax

The <riskdisplay> tag supports these attributes:

  • `model`: (Optional) The name of a risk model defined by a <riskmodel> tag.
  • `placeholder`: (Optional) Wikitext to display while the tag is waiting for user input.
  • `data-*`: (Optional) Defines calculation parameters. If a `model` is provided, these will override the model's parameters. If no `model` is provided, these define the "inline model" parameters.

Basic Syntax (Using a Model)

<riskdisplay model="heart_attack_risk" placeholder="Please select options '''above''' to see your risk"/>

Basic Syntax (Inline Model)

<riskdisplay
  data-base="10"
  data-calc="{{#expr: {base} * {user_age} }}"
>
  Your inline risk is {calc}.
</riskdisplay>

Usage

There are three primary ways to use <riskdisplay>:

  1. Model Only (Recommended) : This is the cleanest and most common use case. You simply reference a pre-defined <riskmodel>. The <riskdisplay> tag will use the model's `data-` parameters and its content.
  2. Model with Overrides : You can reference a model, but override parts of it:
    1. To override parameters, add `data-` attributes to the <riskdisplay> tag. These will be merged with the model's parameters, with the <riskdisplay> tag's attributes taking precedence.
    2. To override the content, simply put new wikitext inside the <riskdisplay> tag.
  3. Inline Model : For simple or one-off calculations, you can define the entire model inside the <riskdisplay> tag. Do not provide a `model` attribute. Instead, define all calculation steps with `data-` attributes and provide the final wikitext as the tag's content.

Examples

Using a Risk Model

Display the result of a risk model named "heart_attack_risk":

<riskdisplay model="heart_attack_risk" />

This uses all the calculations and content from the "heart_attack_risk" <riskmodel>.

Model with Overrides

Use the "HeartRisk" model, but override the `age_risk` parameter and provide new display text:

<riskdisplay model="HeartRisk"
  data-age_risk="0"
  placeholder="Calculating..."
>
  The risk score, ignoring age, is '''{total_score}'''.
</riskdisplay>

Inline Model

Define a simple, self-contained calculation that does not use a <riskmodel>:

<riskdisplay
  data-base="10"
  data-multiplier="{user_age}"
  data-inline_calc="{{#expr: {base} * {multiplier} }}"
  placeholder="Waiting for age..."
>
  This is an inline model.
  The calculation is {base} * {multiplier} = {inline_calc}.
</riskdisplay>

Dynamic Page Content

RiskDisplay can be used to make parts of a page dynamic. This example only shows a DropDown if another DropDown has set the `{travel_mode}` selection to "Train":

<riskdisplay>
  {{#ifeq: {travel_mode}|Train|
    What kind of train: <dropdown table="train_risk"/>
  }}
</riskdisplay>

Notes

  • `data-` attributes (for inline models or overrides) can appear in any order and will be evaluated in the correct dependency order, but circular references (e.g., `data-foo="{bar}"` and `data-bar="{foo}"`) are not allowed.
  • Using MediaWiki Parser Functions like {{#ifexpr:}} or {{#ifeq:}} inside a <riskdisplay> is very powerful.

Troubleshooting

  • Error: "riskdisplay: can't find riskmodel named X" – Ensure the `model` name matches a <riskmodel> on the current page or a "/Data" subpage.
  • Error: "Circular reference detected..." – Your `data-` attributes (either in this tag or in the referenced model) have a logic loop.
  • Result not displayed (or stuck on placeholder) – The display is waiting for one or more placeholders. Add `?debug=1` to the page URL. The RiskDisplay will show exactly which placeholders (e.g., `{age}`, `{user_factor}`) it is waiting for from a DropDown, RiskParameter, or RiskDataLookup.

For related features, see RiskModel documentation or RiskData documentation.