Skip to content

Commit a7518fe

Browse files
committed
Add Content Block documentation
1 parent 595a9e4 commit a7518fe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/tasks/using-content-blocks.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Using content blocks in Smart Answers
2+
3+
You can use content blocks from the [Content Block Manager](https://content-block-manager.publishing.service.gov.uk) in Smart Answers.
4+
This lets you reuse content across multiple Smart Answers, which will automatically update when the content block is updated.
5+
6+
## Content block embed codes
7+
8+
A content block embed code is a short snippet used to embed a content block. It looks like this:
9+
10+
```
11+
{{embed:content_block_contact:information-commissioners-office}}
12+
````
13+
14+
## Using an embed code in a Smart Answer
15+
16+
You can use embed codes in a Smart Answer’s Flow, Calculator or view.
17+
18+
To fetch a content block using an embed code, call the [`ContentBlockTools::ContentBlock.from_embed_code` method](https://github.com/alphagov/govuk_content_block_tools/blob/69f06ce51513e47f2cc2925b933a0de09249a516/lib/content_block_tools/content_block.rb#L69):
19+
20+
```ruby
21+
block = ContentBlockTools::ContentBlock.from_embed_code("{{embed:content_block_contact:information-commissioners-office}}")
22+
````
23+
24+
You can then use the [`render` method](https://github.com/alphagov/govuk_content_block_tools/blob/69f06ce51513e47f2cc2925b933a0de09249a516/lib/content_block_tools/content_block.rb#L93) to return the content block as an HTML string:
25+
26+
```ruby
27+
block.render #=> "<div class=\"content-block content-block--contact\" ..."
28+
```
29+
30+
## Publishing a Smart Answer that uses content blocks
31+
32+
After adding a content block to a Smart Answer, you must [republish the Smart Answer](https://github.com/alphagov/smart-answers/blob/main/docs/tasks/publishing.md).
33+
This ensures the Smart Answer is shown as dependent content in Content Block Manager. It also allows changes to the content block to be previewed in the context of the Smart Answer.
34+
35+
This process uses the [`ContentBlockDetector` class](https://github.com/alphagov/smart-answers/blob/main/app/services/content_block_detector.rb) to detect embedded content blocks and send them to the Publishing API as links.
36+
37+
## Limitations
38+
39+
Because the Content Block Manager’s preview service finds and replaces content blocks within pages, it’s not yet possible to use content blocks in Calculations.
40+
We plan to address this in the future.

0 commit comments

Comments
 (0)