Skip to main content
Warning This document has not been updated for a while now. It may be out of date.
Last updated: 30 Apr 2019

govuk_publishing_components: Use a component

Components are included in templates in slightly different ways depending on whether the component is in the application itself or in the gem.

A component from the application would be included in a template like this:

<%= render "components/back-to-top", href: "#contents" %>

A component from the gem would be included like this:

<%= render "govuk_publishing_components/components/back_link", href: "#" %>

Components can be rendered from outside of a Rails view by calling a render method directly on GovukPublishingComponents.

GovukPublishingComponents.render("govuk_publishing_components/components/back_link", href: "#")

A locale can be specified as an argument to render a component in a particular localisation.

GovukPublishingComponents.render("govuk_publishing_components/components/back_link", href: "#", locale: "cy")