);
diff --git a/designer/client/i18n/translations/en.translation.json b/designer/client/i18n/translations/en.translation.json
index b5eac278e1..b6e13fffe5 100644
--- a/designer/client/i18n/translations/en.translation.json
+++ b/designer/client/i18n/translations/en.translation.json
@@ -69,6 +69,10 @@
"detailsLink": {
"title": "Additional settings"
},
+ "exposeToContextOption": {
+ "helpText": "If using additional context, choose this option to expose the field to be used by additional contexts",
+ "title": "Expose to context"
+ },
"helpTextField": {
"helpText": "Enter the description to show for this field",
"title": "Help text (optional)"
diff --git a/designer/client/reducers/component/componentReducer.options.ts b/designer/client/reducers/component/componentReducer.options.ts
index c09d350056..8b555af45b 100644
--- a/designer/client/reducers/component/componentReducer.options.ts
+++ b/designer/client/reducers/component/componentReducer.options.ts
@@ -128,5 +128,13 @@ export function optionsReducer(state, action: OptionsActions) {
options: { ...options, maxWords: payload },
},
};
+ case Options.EDIT_OPTIONS_EXPOSE_TO_CONTEXT:
+ return {
+ ...state,
+ selectedComponent: {
+ ...selectedComponent,
+ options: { ...options, exposeToContext: payload },
+ },
+ };
}
}
diff --git a/designer/client/reducers/component/types.ts b/designer/client/reducers/component/types.ts
index ee4e8549e1..b3c2c9f08f 100644
--- a/designer/client/reducers/component/types.ts
+++ b/designer/client/reducers/component/types.ts
@@ -51,6 +51,7 @@ export enum Options {
EDIT_OPTIONS_MAX_WORDS = "EDIT_OPTIONS_MAX_WORDS",
EDIT_OPTIONS_PREFIX = "EDIT_OPTIONS_PREFIX",
EDIT_OPTIONS_SUFFIX = "EDIT_OPTIONS_SUFFIX",
+ EDIT_OPTIONS_EXPOSE_TO_CONTEXT = "EDIT_OPTIONS_EXPOSE_TO_CONTEXT",
}
export const Actions = {
diff --git a/docker-compose.smoke.yml b/docker-compose.smoke.yml
index e72ebf0af8..81329979a3 100644
--- a/docker-compose.smoke.yml
+++ b/docker-compose.smoke.yml
@@ -36,6 +36,7 @@ services:
- sandbox=true
- PREVIEW_MODE=true
- NODE_ENV=test
+ - ALLOW_USER_TEMPLATES=true
command: yarn runner start
depends_on:
- redis
diff --git a/docs/runner/templating.md b/docs/runner/templating.md
new file mode 100644
index 0000000000..0115eaf4a3
--- /dev/null
+++ b/docs/runner/templating.md
@@ -0,0 +1,27 @@
+# Templating
+
+If you find yourself faced with a form with content that needs to appear based on different field values, and there's a lot of options to choose from, putting all of this content in conditions may be at best very time-consuming, and at worst crash your form runner.
+
+With this in mind, templating may be a good solution for you.
+
+## How it works
+
+You can allow fields to be exposed to the additional context by adding an `exposeToContext` flag to the component's options. This can be done manually, or through the "expose to context" field in the designer.
+
+Once your field is exposed, the field can be used with additional context by adding the field in titles and html components, using nunjucks templating syntax, `{{ fieldName }}`.
+
+You can also access additional values (such as custom html) using the additional context file. This will allow you to populate different variables based of the same user input, and these can be accessed using the format `{{ additionalContexts.contextName[fieldName].variableName }}`.
+
+There is an example form set up to demonstrate this. If you start your runner, and navigate to http://localhost:3009/html-templating-example, you can choose either option and see the dynamic content on the next page.
+
+## Adding your own additional context
+
+You can add your own additional context by modifying the additional context json, located at `runner/src/server/templates/additionalContexts.json`.
+
+Once you have added your own additionalContext namespace in the same way the example namespace is populated, you'll be able to add your context variables to your html component as stated above e.g for the example form, the list is set by referencing `{{ additionalContexts.example[contentToDisplay].listItems }}`.
+
+### Using nunjucks filters
+
+You can also apply nunjucks filters to your context, for example you may want to add the `safe` filter for printing html content. You would do this the same way you would in normal nunjucks, e.g. `{{ additionalContexts.example[contentToDisplay].listItems | safe }}`.
+
+For more information about what nunjucks filters are available to you, [visit the Nunjucks docs](https://mozilla.github.io/nunjucks/templating.html#filters).
diff --git a/e2e/cypress/e2e/runner/htmlTemplating.feature b/e2e/cypress/e2e/runner/htmlTemplating.feature
new file mode 100644
index 0000000000..5f9d53282c
--- /dev/null
+++ b/e2e/cypress/e2e/runner/htmlTemplating.feature
@@ -0,0 +1,17 @@
+Feature: HTML templating in forms
+
+ Scenario: Correct content should be shown for option one
+ When the form "html-templating-example" exists
+ And I choose "Answer 1"
+ And I continue
+ Then I see "This content is based on answer 1"
+ And I see "Item 1"
+ And I see "Item 2"
+
+ Scenario: Correct content should be shown for option 2
+ When the form "html-templating-example" exists
+ And I choose "Answer 2"
+ And I continue
+ Then I see "This content is based on answer 2"
+ And I see "Item 3"
+ And I see "Item 4"
\ No newline at end of file
diff --git a/e2e/cypress/fixtures/html-templating-example.json b/e2e/cypress/fixtures/html-templating-example.json
new file mode 100644
index 0000000000..5052cc6eb9
--- /dev/null
+++ b/e2e/cypress/fixtures/html-templating-example.json
@@ -0,0 +1,63 @@
+{
+ "metadata": {},
+ "startPage": "/which-content-do-you-want-to-display",
+ "pages": [
+ {
+ "title": "Which content do you want to display?",
+ "path": "/which-content-do-you-want-to-display",
+ "components": [
+ {
+ "name": "contentToDisplay",
+ "options": { "exposeToContext": true },
+ "type": "RadiosField",
+ "title": "Content to display",
+ "list": "vYTQRu",
+ "nameHasError": false,
+ "values": { "type": "listRef" },
+ "schema": {}
+ }
+ ],
+ "next": [{ "path": "/second-page" }],
+ "section": "gcdSFb"
+ },
+ {
+ "path": "/second-page",
+ "title": "Dynamic page based on your answers: {{ contentToDisplay }}",
+ "components": [
+ {
+ "name": "azSyOn",
+ "options": {},
+ "type": "Html",
+ "content": "
This page demonstrates how templating works.
\n
Depending on the answer you chose for the first question, you should see different content displayed below.