Skip to content

Commit

Permalink
Allow heading blocks to accept an id for an anchor link
Browse files Browse the repository at this point in the history
  • Loading branch information
leenagupte committed Nov 29, 2024
1 parent a044a3d commit 3672992
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/landing_page/blocks/_heading.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
%>
<%= render "govuk_publishing_components/components/heading", {
text: govuk_styled_link(text, path:, inverse:),
id: block.data["id"],
font_size: font_size,
heading_level: heading_level,
margin_bottom: margin_bottom,
Expand Down
3 changes: 3 additions & 0 deletions docs/building_blocks_for_flexible_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ When added through Whitehall content can either be written in HTML or govspeak m

A wrapper around the [Heading component](https://components.publishing.service.gov.uk/component-guide/heading). This block uses `content` where the component uses `text` for the title text key. This is so that headings can appear in search (only values inside a `content` key will be indexed when being published from Whitehall - see [Indexing block content in search](#indexing-block-content-in-search))

If an `id` is added, the heading can be referenced in an anchor link.

```yaml
- type: heading
id: heading-id
content: Porem ipsum dolor
```

Expand Down
8 changes: 8 additions & 0 deletions lib/data/landing_page_content_items/exercise_more.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ navigation_groups:
href: "/landing-page/learn-something-new"
- text: Be thankful
href: "/landing-page/be-thankful"
- heading: Exercise more
links:
- text: Anchor link one
href: "/landing-page/exercise-more#anchor-one"
- text: Anchor link two
href: "/landing-page/exercise-more#anchor-two"
- id: Sidebar
links:
- text: Be kinder
Expand Down Expand Up @@ -146,6 +152,7 @@ blocks:
accumsan, risus sem sollicitudin lacus, ut interdum tellus elit sed risus.
Maecenas eget.</p>
- type: heading
id: anchor-one
content: Porem ipsum dolor
- type: govspeak
content: |
Expand All @@ -156,6 +163,7 @@ blocks:
Maecenas eget.</p>
- type: heading
content: Porem ipsum dolor
id: anchor-two
- type: document_list
taxon_base_path: /government/government-efficiency-transparency-and-accountability
items:
Expand Down

0 comments on commit 3672992

Please sign in to comment.