Skip to content

Commit

Permalink
Merge pull request #240 from alphagov/document-or
Browse files Browse the repository at this point in the history
Show content when data is blank using `or`
  • Loading branch information
oli-rose28 authored Jul 6, 2023
2 parents 897d770 + 2d2a5b1 commit c514d96
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/v13/documentation/pass-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ Most inputs use the `value` option:

For checkboxes the option is `values`, since more than one can be selected.

### Show content if users have not answered optional questions

You can show content if data is currently blank using `or`, for example:

```
{{ data['first-name'] or "First name not given" }}
```

You can also use this in a component. For example to show that a user has not answered an optional question on Check your answers:

```
{{ govukSummaryList({
rows: [
{
key: {
text: "First name"
},
value: {
text: data['first-name'] or "First name not given"
}
}
]
})}}
```


### Set default data

You can set default data in your prototype. This will appear without the user having to enter anything.
Expand Down

0 comments on commit c514d96

Please sign in to comment.