Data and functions
Using a consistent set of data across prototypes helps us to build consistent pages.
Getting started
-
Install the example plugin
Terminal window npm install git@github.com:htmlandbacon/govuk-prototype-personas.git -
Then we can get a citzen in the view
{% set citizen = getCitizenBySlug("stan_wisozk") %}<p class="govuk-body">Hello {{ citizen.name }}.</p>
We an also output a list of all citizens with the following:
{% set citizens = getCitizens() %}
{% for citizen in citizens %} <p class="govuk-body">Hello {{ citizen.name }}.</p>{% endfor %}
Once it has been installed we can also use the same methods in our routes.js file and pass the data into our view.
In the view, we can access the data by using the citizen
object.
// add this to your routes.js file// import the required functionconst { getCitizenBySlug } = require("govuk-prototype-personas")
router.get("/show-citizen", (req, res) => { // look up the citizen const citizen = getCitizenBySlug("stan_wisozk"); // pass citizen into the view res.render("citizen.njk", { citizen })})
Test data was generated user faker.js.