Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nunjucks render helpers from forms designer #552

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Nov 22, 2024

This PR brings over the Nunjucks helpers we use on forms-designer

import * as render from '~/src/server/plugins/nunjucks/render.js'

render.macro()
render.string()
render.view()

I've used it as a good opportunity to migrate the views plugin from TypeScript to plain ES modules

Nunjucks within view models

Why is this helpful?

  1. Nunjucks views need tests too
  2. Nunjucks strings and macros often need evaluating earlier

For example, see where we safely encode notification emails in forms-designer using:

render.string(
  'Completed forms will be sent to <a href="mailto:{{ notificationEmail | urlencode }}" class="govuk-link">{{ notificationEmail }}</a>.',
  { context: form }
)

Or alternatively, rendering a macro without string-building raw HTML

render.macro('summaryValue', 'partials/summary-value.html', {
  params: item
})

@colinrotherham colinrotherham force-pushed the nunjucks-environment branch 2 times, most recently from 0d588fb to df84422 Compare November 22, 2024 12:52
@colinrotherham colinrotherham changed the title Add Nunjucks render helpers Add Nunjucks render helpers from forms runner Nov 22, 2024
@colinrotherham colinrotherham changed the title Add Nunjucks render helpers from forms runner Add Nunjucks render helpers from forms designer Nov 22, 2024
@colinrotherham colinrotherham force-pushed the nunjucks-environment branch 2 times, most recently from 8d98e63 to 94d51d2 Compare November 22, 2024 17:14
@colinrotherham colinrotherham changed the base branch from type-formatting to main November 22, 2024 17:16
Copy link

sonarcloud bot commented Nov 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant