{"id":37135662,"url":"https://github.com/onsdigital/dp-renderer","last_synced_at":"2026-01-14T15:49:04.831Z","repository":{"id":36950302,"uuid":"378850597","full_name":"ONSdigital/dp-renderer","owner":"ONSdigital","description":"The rendering library for Digital Publishing frontend services","archived":false,"fork":false,"pushed_at":"2025-07-18T11:47:23.000Z","size":922,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-07-18T15:40:48.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ONSdigital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-21T07:53:25.000Z","updated_at":"2025-07-18T11:32:22.000Z","dependencies_parsed_at":"2023-02-18T05:15:31.447Z","dependency_job_id":"736363f3-b915-48d4-a635-0c5380622785","html_url":"https://github.com/ONSdigital/dp-renderer","commit_stats":null,"previous_names":[],"tags_count":146,"template":false,"template_full_name":null,"purl":"pkg:github/ONSdigital/dp-renderer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ONSdigital%2Fdp-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ONSdigital%2Fdp-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ONSdigital%2Fdp-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ONSdigital%2Fdp-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ONSdigital","download_url":"https://codeload.github.com/ONSdigital/dp-renderer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ONSdigital%2Fdp-renderer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28425075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T15:24:48.085Z","status":"ssl_error","status_checked_at":"2026-01-14T15:23:41.940Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T15:49:04.214Z","updated_at":"2026-01-14T15:49:04.822Z","avatar_url":"https://github.com/ONSdigital.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dp-renderer\n\n---\n\n:warning: This library is deprecated and is no longer in active development. Use `dis-design-system-go` instead. Follow the [instructions](https://github.com/ONSdigital/dis-design-system-go/blob/main/MIGRATION.md) to migrate your app. :warning:\n\n---\n\nA rendering library for Digital Publishing frontend microservices. `dp-renderer` contains templates, localisations and model structs that are core to all `dp-frontend` services.\n\n`dp-renderer` is intended to be used instead of calling `dp-frontend-renderer` to generate HTML, which consequently means more explicit domain encapsulation of our frontend apps and the removal of a single point of failure within the DP frontend architecture.\n\nNote: although the `dp-frontend-renderer` is deprecated there is a transition period where updates will be needed in `dp-renderer` and the `dp-frontend-renderer`. See the README on the `dp-frontend-renderer` for the migration status.\n\n## Installation\n\nOther than `dp-renderer` itself, you will need a utility that can combine service-specific and `dp-renderer` assets. We currently use `go-bindata` for this process.\n\n- `dp-renderer`: `go get github.com/ONSdigital/dp-renderer/v2`\n\n\u003e You can specify a version of `dp-renderer` by appending a commit ID or semantic version number to this command. E.g., `go get github.com/ONSdigital/dp-renderer/v2@d27f174`\n\n- `go-bindata`: `go get github.com/kevinburke/go-bindata`\n\n## Migrating from `dp-frontend-renderer` and `dp-frontend-models` to using `dp-renderer`\n\nSee the [migration](MIGRATION.md) guide for step-by-step details.\n\n## Usage\n\n### Instantiation\n\nAssuming you have `go-bindata` set up to generate the relevant asset helper functions, you can instantiate the renderer with a default client (in this case, the default client is [`unrolled`](https://github.com/unrolled/render)).\n\n```go\nrend := render.NewWithDefaultClient(asset.Asset, asset.AssetNames, cfg.PatternLibraryAssetsPath, cfg.SiteDomain)\n```\n\nYou can also instantiate a `Render` struct without a default client by using `New()`. This requires a rendering client that fulfills the `Renderer` interface to be passed in as well.\n\n```go\nrend := render.New(rendereringClient, patternLibPath, siteDomain)\n```\n\n### Mapping data and building a page\n\nWhen mapping data to a page model, you can use `NewBasePageModel` to instantiate a base page model with its `PatternLibraryAssetsPath` and `SiteDomain` properties auto-populated via the `Render` struct:\n\n```go\nbasePage := rendC.NewBasePageModel()\nmappedPageData := mapper.CreateExamplePage(basePage)\n```\n\nIn order to generate HTML from a page model and template, use `BuildPage`, passing in the `ResponseWriter`, mapped data, and the name of the template:\n\n```go\nrend.BuildPage(w, mappedPageData, \"name-of-template-file-without-extension\")\n```\n\nIf an error occurs during page build, either because of an incorrect template name or incorrect data mapping, `dp-renderer` will write an error via an `errorResponse` struct.\n\n### Using design patterns or components in your service\n\nSee [PATTERNS](PATTERNS.md) for details.\n\n### Using Sixteens for older pages\n\nAs Sixteens is in the process of being deprecated, dp-renderer is designed to use [`dp-design-system`](https://github.com/ONSdigital/dp-design-system) by default.\n\nIf a page requires Sixteens instead of dp-design-system, then you need to set the `FeatureFlag.SixteensVersion` to the relevant Sixteens commit ID. When this value is set, the main template will load Sixteens assets and styling instead of the design system's.\n\n```go\nfunc CreateExamplePage(basePage coreModel.Page) model.ExamplePage {\n    p := model.ExamplePage{\n        Page: basePage\n    }\n\n    // Loads in specific version of Sixteens based on commit ID, instead of dp-design-system\n    p.FeatureFlags.SixteensVersion = \"ba32e79\"\n    \n    return p\n}\n```\n\n### Referencing a local instance of dp-renderer in a docker container\n\nIf you are running and developing within a docker container that includes references to the dp-renderer, for example, the [cantabular import journey](https://github.com/ONSdigital/dp-compose/tree/main/cantabular-import). Follow these steps to use a local instance:\n\n- Update the `go.mod` file in the relevant service to use the `replace statement` to point to your local dp-renderer instance\ne.g.\n\n```go\nreplace \"github.com/ONSdigital/dp-renderer/v2\" =\u003e \"/{yourPathToLocalGitDirectory}/dp-renderer\"\n```\n\n- Add the volume of your local instance to the service's `.yaml` file in dp-compose\ne.g.\n\nTo modify the [dp-frontend-dataset-controller](https://github.com/ONSdigital/dp-frontend-dataset-controller) to use a local dp-renderer instance in the cantabular import journey, modify `dp-frontend-dataset-controller.yml` volumes to include your local instance\n\n```yml\nversion: '3.3'\nservices:\n    dp-frontend-dataset-controller:\n        build:\n            context: ../../dp-frontend-dataset-controller\n            dockerfile: Dockerfile.local\n        command:\n            - reflex\n            - -d\n            - none\n            - -c\n            - ./reflex\n        volumes:\n            - ../../dp-frontend-dataset-controller:/dp-frontend-dataset-controller\n            - /{yourPathToLocalGitDirectory}/dp-renderer:/{yourPathToLocalGitDirectory}/dp-renderer\n        ports:\n            - 20200\n        restart: unless-stopped\n        environment:\n            BIND_ADDR:                \":20200\"\n            DOWNLOAD_SERVICE_URL:     \"http://dp-download-service:23600\"\n            API_ROUTER_URL:           \"http://dp-api-router:23200/v1\"\n            DOWNLOADER_URL:           \"http://dp-download-service:23400\"\n            ENABLE_CENSUS_PAGES:      \"true\"\n```\n\n### Using the `scripts` partial to load scripts specific to a route \nIf a frontend web app requires extra custom scripts to be loaded specific to a route\nthen you can use github.com/unrolled/render `partial` nested templates. \n\nFor example, you could have a peer dependency npm package like `mapbox-gl` \u0026 dynamically\nload that only for pages displaying a map. Because we have defined a `{{ partial \"scripts\" }}` in \nthe `main.tmpl` file in this repo, we can use this partial in each frontend that declares a `{{ define \"scripts-\u003cTEMPLATE_NAME\u003e\" }}`\n\nFor example, in Area Profiles frontend web app `/areas` endpoint renders a `area-summary.tmpl` template file.\nTherefore, we must use the partial name follwed by the the frontends tempalte name: `\"scripts-area-summary\"`\n```\n{{ define \"scripts-area-summary\" }}\n    \u003cscript src=\"/assets/dist/mapboxGL.bundle.js?v={{ .Version }}\"\u003e\u003c/script\u003e\n    \u003cscript src=\"/assets/dist/areaLanding.bundle.js?v={{ .Version }}\"\u003e\u003c/script\u003e\n{{ end }}\n```\n\nRead more about the Unrolled's `partial` function [here](https://github.com/unrolled/render#layouts) \n## Contributing\n\nSee [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## License\n\nCopyright © 2024, Office for National Statistics (\u003chttps://www.ons.gov.uk\u003e)\n\nReleased under MIT license, see [LICENSE](LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsdigital%2Fdp-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonsdigital%2Fdp-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsdigital%2Fdp-renderer/lists"}