class GovukNavigationHelpers::RelatedItems
Generate data for the “Related Items” component
govuk-component-guide.herokuapp.com/components/related_items
The procedure to group the links is quite complicated. In short, related links are grouped by how related they are to the current page.
The wiki page on related items has more information:
gov-uk.atlassian.net/wiki/pages/viewpage.action?pageId=99876878
Attributes
content_item[R]
Public Class Methods
new(content_item)
click to toggle source
# File lib/govuk_navigation_helpers/related_items.rb, line 16 def initialize(content_item) @content_item = ContentItem.new(content_item) end
Public Instance Methods
Private Instance Methods
grouped()
click to toggle source
# File lib/govuk_navigation_helpers/related_items.rb, line 88 def grouped @grouped ||= GroupedRelatedLinks.new(content_item) end
parents_tagged_to_same_mainstream_browse_page_section()
click to toggle source
# File lib/govuk_navigation_helpers/related_items.rb, line 48 def parents_tagged_to_same_mainstream_browse_page_section return unless grouped.parents_tagged_to_same_mainstream_browse_page.any? items = grouped.parents_tagged_to_same_mainstream_browse_page.map do |related_item| { title: related_item.title, url: related_item.base_path } end { title: content_item.parent.parent.title, url: content_item.parent.parent.base_path, items: items } end
tagged_to_different_mainstream_browse_pages_section()
click to toggle source
# File lib/govuk_navigation_helpers/related_items.rb, line 61 def tagged_to_different_mainstream_browse_pages_section return unless grouped.tagged_to_different_mainstream_browse_pages.any? items = grouped.tagged_to_different_mainstream_browse_pages.map do |related_item| { title: related_item.title, url: related_item.base_path } end { title: "Elsewhere on GOV.UK", items: items } end
tagged_to_same_mainstream_browse_page_section()
click to toggle source
# File lib/govuk_navigation_helpers/related_items.rb, line 35 def tagged_to_same_mainstream_browse_page_section return unless grouped.tagged_to_same_mainstream_browse_page.any? items = grouped.tagged_to_same_mainstream_browse_page.map do |related_item| { title: related_item.title, url: related_item.base_path } end { title: content_item.parent.title, url: content_item.parent.base_path, items: items } end