Question templates live in app/flows/<flow-name>/questions/<question-name>.erb
.
The templates can contain content for any of the following keys:
Used as the h1 heading and can only be text. Example:
<% text_for :title do %>
How much milk proteins does the product contain?
<% end %>
Used as a "hint" paragraph and can be text. For money and radio questions you can also use govspeak or HTML. Example:
<% govspeak_for :hint do %>
Examples of some fruit:
- apple
- orange
- banana
<% end %>
Used as a "caption" paragraph and can only be text. Example:
<% text_for :caption do %>
This is a caption
<% end %>
If :caption
is not supplied the :title
(i.e. the flow name) from the start_node
is used.
Used as a label (preceding the input control) for value questions. Can only be text. Example:
<% text_for :label do %>
Hours per shift
<% end %>
Note: As of May 2020 this option may not be working correctly. Please check and amend this documentation.
Valid for value questions & money questions. Can only be text. Example:
<% text_for :suffix_label do %>
years old
<% end %>
Used to generate the main content (appearing above the input control, e.g. text input element). It is valid for all questions types and can be govspeak or HTML. Example:
<% govspeak_for :body do %>
An introduction to a question.
<% end %>
Used to generate supplementary content (appearing below the input control). It is valid for all question types and can be govspeak or HTML. Example:
<% html_for :post_body do %>
<p>A conclusion to a question</p>
<% end %>
Error message for the default validation error key. Can only be text. Example:
<% text_for :error_message do %>
Try again
<% end %>
Note you can specify error messages for a custom validation error key. These
can be specified with a prefix of :error_
,
Example:
<% text_for :error_for_a_specific_scenario do %>
Try again
<% end %>
This is done using a call to the options
method.
Valid for radio and checkbox question types. hash
argument is a Hash
of option keys (strings) and values (strings or hashes).
It is used to specify the human-readable label text or hint text for each of the option keys.
Example with only label text:
<% options(
"apple": "Apple",
"banana": "Bananas",
"red-grapes": "Red grapes"
) %>
Example with label text and hint text:
<% options(
"apple": "Apple",
"gooseberry": {
label: "Gooseberry",
hint_text: "These can be sour"
},
"red-grapes": "Red grapes"
) %>
If you need hide the caption text above the question text. This can be set using the following method:
<% hide_caption true %>
By default the caption is shown (hide_caption false
).