FamilyHubs.SharedKernel.Razor
2.3.0
See the version list below for details.
dotnet add package FamilyHubs.SharedKernel.Razor --version 2.3.0
NuGet\Install-Package FamilyHubs.SharedKernel.Razor -Version 2.3.0
<PackageReference Include="FamilyHubs.SharedKernel.Razor" Version="2.3.0" />
paket add FamilyHubs.SharedKernel.Razor --version 2.3.0
#r "nuget: FamilyHubs.SharedKernel.Razor, 2.3.0"
// Install FamilyHubs.SharedKernel.Razor as a Cake Addin #addin nuget:?package=FamilyHubs.SharedKernel.Razor&version=2.3.0 // Install FamilyHubs.SharedKernel.Razor as a Cake Tool #tool nuget:?package=FamilyHubs.SharedKernel.Razor&version=2.3.0
Family Hub web framework and components
This package is designed to work in conjunction with the familyhubs-frontend node package, to rapidly create new GOV.UK websites and add standard components.
It builds on top of theses packages:
The package contains:
- configurable standard GOV.UK layout (although only the DfE header is included)
- configurable header and footer links
- cookie banner and page with pluggable content
- Google Analytics support
- GOV.UK pagination support
- Error handling, error pages and GOVUK error summary component
- MOJ dashboard support
- alternative configs for when pages need different layouts, headers, footers etc.
- Url helpers for picking Urls from config, manipulating them and inheriting them from ancestor configs
- a set of SASS files that import the above packages and add some additional styling
- .NET distributed cache support for SQL Server and Redis
- JavaScript postcode helpers
- HTTP security header support
There is an example ASP.Net 7 site that shows how to use the packages.
Consuming the packages
Install the familyhubs-frontend package into the website project using the following command:
npm install familyhubs-frontend
Installing the package, will add files to the wwwroot folder. (todo document which files)
In the styles/application.scss file, add the following line:
@import "../node_modules/familyhubs-frontend/styles/all";
Add the FamilyHubs.SharedKernel.Razor package to the website project.
The FamilyHubs.SharedKernel.Razor package contains:
- the layout
- common shared partial views
- todo add rest here
Check that the npm package and the Razor Class Library are on the same version.
Add the configuration section to the appsettings.json file of the website project.
Configuration
Here's an example configuration section that should be added to the appsettings.json file of a Family Hubs website:
"FamilyHubsUi": {
"ServiceName": "Manage family support services and accounts",
"Phase": "Beta",
"FeedbackUrl": "https://example.com/feedback",
"SupportEmail": "find-support-for-your-family.service@education.gov.uk",
"Analytics": {
"CookieName": "manage_family_support_cookies_policy",
"CookieVersion": 1,
"MeasurementId": "",
"ContainerId": ""
},
"Header": {
"NavigationLinks": [
{ "Text": "Requests Sent", "Url": "https://dev.manage-connection-requests.education.gov.uk/" },
{ "Text": "Search for service", "Url": "/ProfessionalReferral/Search" },
],
"ActionLinks": [
{ "Text": "My account", "Url": "/account/my-account" },
{ "Text": "Sign out", "Url": "/account/signout" }
]
},
"Footer": {
"Links": [
{ "Text": "Accessibility" },
{ "Text": "Contact Us" },
{ "Text": "Cookies" },
{ "Text": "Feedback", "ConfigUrl": "FamilyHubsUi:FeedbackUrl" },
{ "Text": "Terms and conditions" }
]
}
Notes:
Google Analytics is only enabled if the MeasurementId and ContainerId are set.
The Options classes have XML documentation on the properties.
If your cookie page is at a different location to
/cookies
, you can set it usingCookiePageUrl
in theAnalytics
section.
Version numbers
To ease testing, we should keep the version number of the NPM package and the Razor Class Library in sync. Consumers should then ensure that both packages are on the same version.
The version of the familyhubs-frontend package is given in its package.json file, as the value of the version property.
The version of the FamilyHubs.SharedKernel.Razor package is given in its FamilyHubs.SharedKernel.Razor.csproj file, as the value of the VersionPrefix property.
familyhubs-frontend
To publish this npm package, you�ll need to follow these steps:
- Create a user account on the npm website if you don�t already have one.
- In your terminal or command prompt, navigate to the
familyhubs-frontend
directory, containing the package files. - Run the
npm login
command and enter your npm username, password, and email when prompted. - Update the package.json file in the package directory with the version number synced to the FamilyHubs.SharedKernel.Razor version.
- Run the
npm publish
command to publish the package to the npm registry.
After publishing the package, it will be available for others to install and use nearly instantaneously.
It's best to reference the package using its exact version number, otherwise it might not pick up the latest, just published version.
FamilyHubs.SharedKernel.Razor
The package is automatically built when the solution is built.
It is not currently published automatically to the NuGet feed, and needs to be manually uploaded to NuGet.
Components
Cookie page
Call AddCookiePage()
on your IServiceCollection
, like so...
services.AddCookiePage(configuration);
Create a new Razor Page. Inject ICookiePage into the PageModel's constructor, stash it away, then pass it to the cookie page partial in the View.
To add support for users running without Javascript, add an OnPost method as per the example.
E.g.
public class IndexModel : PageModel
{
public readonly ICookiePage CookiePage;
public IndexModel(ICookiePage cookiePage)
{
CookiePage = cookiePage;
}
public void OnPost(bool analytics)
{
CookiePage.OnPost(analytics, Request, Response);
}
}
and add in your view...
<partial name="~/Pages/Shared/_CookiePage.cshtml" model="Model.CookiePage"/>
Add a partial view called Pages/Shared/_CookiePolicy.cshtml
and add the cookie policy content into it.
If you want to pick up the cookie policy content from a different partial view, pass its name into AddCookiePage()
, e.g.
services.AddCookiePage(configuration, "SomeOtherView.cshtml");
User-friendly, branded error pages
To add user-friendly Family Hub branded error pages, call UseErrorHandling()
on WebApplication
, e.g.
app.UseErrorHandling();
By default, the error handling middleware will only be added if it's not the development environment. If you want to always add it, irrespective of the environment (useful for local testing), pass true
as the first parameter.
If SupportEmail
is set in the configuration, the error page will include a link to the given support email address.
To test the not found page, navigate to a URL that doesn't exist, e.g. /not-found
.
To test the error page, navigate to /error/test
, which is a fault-injection page included in the library, explicitly for testing the error page handling.
Release Notes
2.3.0
Update libraries:
2.2.1
Support BaseUrl inheritance in configured links.
2.2.0
When calling Url<>()
on an alternative FamilyHubsUiOptions
, if the Url isn't present in the alternative's Url config section, it will traverse the alternative's ancestors looking for the nearest instance of the Url.
This allows inheritance of Urls from ancestors, whilst still allowing the overriding of Urls.
2.1.0
Add support to allow link status to be set in config and/or during [Navigation|Action]Links() calls.
2.0.0
New major version as contains breaking changes.
Improvements to header links handling to provide more flexibility.
ServiceName
in FamilyHubsUiOptions
is now optional. This allows consumers to use components without having to use the layout or provide a dummy ServiceName
.
Update GOV.UK Frontend to v4.7.0.
1.16.0
Add ability to change header links per page.
See, IFamilyHubsHeader.NavigationLinks()
and IFamilyHubsHeader.ActionLinks()
.
1.15.1
Fix reference to our js file in the layout.
1.15.0
_Layout.cshtml
now has a Head
section for inserting page specific content at the end of the head section.
1.14.0
Support query params/fragment in the relativeUrl param to FamilyHubsUiOptions.Url<>()
.
1.13.0
Add support for header and footer links that have a BaseUrlKey
value that contains a path component.
1.12.0
Fix FamilyHubsUiOptions.Url<>()
when the base URL has a path component.
1.11.0
Add GetAlternative()
method to FamilyHubsUiOptions
to get alternative service config.
1.10.0
Add GetFamilyHubsUiOptions()
and other helper extension methods to ViewDataDictionary
1.9.0 & 1.8.0
Add support for alternative service layout by page (see Alternative example page)
1.7.0
Adds optional configurable link for the header (see Header:ServiceNameLink
)
1.6.0
Add Url()
helper to FamilyHubsUiOptions
1.5.0
Adds:
- BaseUrlKey support in header and footer links
1.4.0
Adds:
- Url helpers (
Html.FamilyHubUrl
&Html.FamilyHubConfigUrl
) - static DontShow pagination instances (
IPagination.DontShow
&ILinkPagination.DontShow
)
See the example site for usage.
Notes:
- This version requires
_ViewStart.cshtml
to not be overridden in the consuming project. If you need to override_ViewStart.cshtml
, ensure the contents of the version in this package is included in your overridden version. A later version might contain a helper for this.
Possible ToDos
move common readme sections into their own files and link to them from both package's readmes
if url not in alternative, could look in parents (to reduce dupes)
add partial to output an <a> from a FhLinkOptions? worth the bother??
use config exceptions
add sign out link on error pages if signed in
navigation menu button visible on mobile if no nav links
better way than solution folders/files for grouping files? show all files and no solution items perhaps?
pick up jquery from cdn with a fallback to our own copy
add uncompressed govuk js
minify moj js
move lib js into lib folder?
chrome/.net sometimes seems to get confused by asp-append-version. it doesn't seem to pick up that the file's changed and fetches the correct file, but also picks stuff up from cache. find a solution <script src="~/js/app.js" asp-append-version="true"></script> or is it an issue with the map file?
add _viewstart to rcl?
use partial for error pages?
finish documenting how to use as a consumer, and how to develop
delete old wwwroot files on install?
use asp-append-version to simplify updating versions??
remove scripts support from private gulpfile?
Use Components/, rather than scripts and styles, a la govuk?
only run postinstall script when consumer is installing, rather than running npm install locally
If you are using Windows, you can use a different approach to achieve the same behavior. One way to do this is to use a Node.js script to check the value of the npm_config_global environment variable and run the gulp task if necessary. Here�s an example of how you can do this:
// postinstall.js const { spawn } = require('child_process');
if (process.env.npm_config_global !== 'true') { spawn('gulp', ['copy-packages-js'], { stdio: 'inherit' }); } In this example, we have created a Node.js script postinstall.js that checks the value of the npm_config_global environment variable. If the value is not "true", then the script spawns a new process to run the gulp copy-packages-js command.
You can use this script as your postinstall script by adding it to the scripts section of your package.json file:
{ "scripts": { "postinstall": "node postinstall.js" }, "dependencies": { "gulp": "^4.0.2" } } With this setup, when you run npm install in your package�s source code directory or when you run npm install my-package to add the package as a dependency of another package, the postinstall.js script will be run and will check whether the package is being installed globally or not. If it is not being installed globally, then the copy-packages-js gulp task will be executed.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Caching.SqlServer (>= 7.0.10)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 7.0.10)
- Microsoft.Extensions.Hosting (>= 7.0.1)
- NetEscapades.AspNetCore.SecurityHeaders (>= 0.20.0)
- StackExchange.Redis (>= 2.6.122)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.5.1 | 1,387 | 9/12/2024 |
9.5.0 | 221 | 8/27/2024 |
9.4.0 | 116 | 8/23/2024 |
9.3.5 | 117 | 8/23/2024 |
9.3.4 | 3,072 | 8/14/2024 |
9.3.3 | 130 | 8/8/2024 |
9.3.2 | 104 | 8/8/2024 |
9.3.1 | 3,647 | 6/21/2024 |
9.3.0 | 125 | 6/20/2024 |
9.2.2 | 505 | 5/21/2024 |
9.2.1 | 157 | 5/16/2024 |
9.2.0 | 109 | 5/13/2024 |
9.1.7 | 715 | 5/2/2024 |
9.1.6 | 559 | 4/10/2024 |
9.1.5 | 1,177 | 3/21/2024 |
9.1.4 | 107 | 3/21/2024 |
9.1.3 | 197 | 3/19/2024 |
9.1.2 | 107 | 3/19/2024 |
9.1.1 | 100 | 3/19/2024 |
9.1.0 | 131 | 3/15/2024 |
9.0.0 | 410 | 2/23/2024 |
8.4.0 | 320 | 2/16/2024 |
8.3.0 | 217 | 2/13/2024 |
8.2.0 | 157 | 2/9/2024 |
8.1.2 | 150 | 2/9/2024 |
8.1.1 | 415 | 1/26/2024 |
8.1.0 | 100 | 1/26/2024 |
8.0.1 | 117 | 1/25/2024 |
8.0.0 | 119 | 1/25/2024 |
7.4.0 | 154 | 1/22/2024 |
7.3.3 | 166 | 1/19/2024 |
7.3.2 | 152 | 1/18/2024 |
7.3.1 | 120 | 1/18/2024 |
7.3.0 | 122 | 1/17/2024 |
7.2.0 | 186 | 1/15/2024 |
7.1.0 | 153 | 1/12/2024 |
7.0.0 | 120 | 1/12/2024 |
6.6.3 | 238 | 12/22/2023 |
6.6.2 | 160 | 12/21/2023 |
6.6.1 | 165 | 12/19/2023 |
6.6.0 | 103 | 12/19/2023 |
6.5.0 | 171 | 12/14/2023 |
6.4.0 | 403 | 11/29/2023 |
6.3.0 | 380 | 11/24/2023 |
6.2.0 | 157 | 11/21/2023 |
6.1.1 | 292 | 11/14/2023 |
6.1.0 | 137 | 11/13/2023 |
6.0.0 | 136 | 11/10/2023 |
5.8.0 | 196 | 11/1/2023 |
5.7.0 | 352 | 10/19/2023 |
5.6.0 | 191 | 10/17/2023 |
5.5.0 | 193 | 10/6/2023 |
5.4.0 | 135 | 10/3/2023 |
5.3.0 | 176 | 9/27/2023 |
5.2.0 | 244 | 9/20/2023 |
5.1.0 | 118 | 9/20/2023 |
5.0.0 | 121 | 9/19/2023 |
4.0.1 | 205 | 9/14/2023 |
4.0.0 | 160 | 9/12/2023 |
3.1.1 | 213 | 9/8/2023 |
3.1.0 | 131 | 9/8/2023 |
3.0.1 | 168 | 9/7/2023 |
3.0.0 | 155 | 9/6/2023 |
2.4.0 | 149 | 9/5/2023 |
2.3.1 | 155 | 9/4/2023 |
2.3.0 | 158 | 8/31/2023 |
2.2.1 | 167 | 8/30/2023 |
2.2.0 | 138 | 8/29/2023 |
2.1.0 | 138 | 8/29/2023 |
2.0.0 | 136 | 8/25/2023 |
1.16.0 | 142 | 8/24/2023 |
1.15.1 | 193 | 8/24/2023 |
1.15.0 | 165 | 8/23/2023 |
1.14.0 | 145 | 8/16/2023 |
1.13.0 | 107 | 8/7/2023 |
1.12.0 | 116 | 8/3/2023 |
1.11.0 | 202 | 7/20/2023 |
1.10.0 | 105 | 7/20/2023 |
1.8.0 | 107 | 7/19/2023 |
1.7.0 | 109 | 7/18/2023 |
1.6.0 | 107 | 7/17/2023 |
1.5.0 | 97 | 7/17/2023 |
1.4.0 | 99 | 7/13/2023 |
1.3.0 | 191 | 7/7/2023 |
1.2.0 | 95 | 7/7/2023 |
1.1.0 | 526 | 6/30/2023 |
1.0.66-alpha | 228 | 6/22/2023 |
1.0.65-alpha | 80 | 6/21/2023 |
1.0.64-alpha | 230 | 6/8/2023 |
1.0.63-alpha | 87 | 6/7/2023 |
1.0.62-alpha | 71 | 6/7/2023 |
1.0.61-alpha | 72 | 6/7/2023 |
1.0.60-alpha | 74 | 6/7/2023 |
1.0.59-alpha | 83 | 6/7/2023 |
1.0.58-alpha | 82 | 6/7/2023 |
1.0.57-alpha | 88 | 6/6/2023 |
1.0.56-alpha | 142 | 6/5/2023 |
1.0.55-alpha | 101 | 6/1/2023 |
1.0.54-alpha | 141 | 5/30/2023 |
1.0.53-alpha | 92 | 5/30/2023 |
1.0.52-alpha | 99 | 5/30/2023 |
1.0.51-alpha | 85 | 5/30/2023 |
1.0.50-alpha | 203 | 5/25/2023 |
1.0.49-alpha | 106 | 5/25/2023 |
1.0.48-alpha | 103 | 5/25/2023 |
1.0.47-alpha | 124 | 5/24/2023 |
1.0.46-alpha | 106 | 5/24/2023 |
1.0.45-alpha | 173 | 5/19/2023 |
1.0.44-alpha | 121 | 5/18/2023 |
1.0.43-alpha | 112 | 5/18/2023 |
1.0.42-alpha | 136 | 5/17/2023 |
1.0.41-alpha | 106 | 5/17/2023 |
1.0.40-alpha | 96 | 5/16/2023 |
1.0.39-alpha | 121 | 5/16/2023 |
1.0.38-alpha | 94 | 5/16/2023 |
1.0.37-alpha | 125 | 5/16/2023 |
1.0.36-alpha | 117 | 5/16/2023 |
1.0.35-alpha | 103 | 5/16/2023 |
1.0.34-alpha | 603 | 4/19/2023 |
1.0.33-alpha | 135 | 4/19/2023 |
1.0.32-alpha | 146 | 4/17/2023 |
1.0.31-alpha | 125 | 4/11/2023 |
1.0.30-alpha | 132 | 3/31/2023 |
1.0.29-alpha | 121 | 3/31/2023 |
1.0.28-alpha | 127 | 3/31/2023 |
1.0.27-alpha | 116 | 3/31/2023 |
1.0.26-alpha | 127 | 3/31/2023 |
1.0.25-alpha | 122 | 3/31/2023 |
1.0.24-alpha | 114 | 3/31/2023 |
1.0.23-alpha | 111 | 3/31/2023 |
1.0.22-alpha | 119 | 3/31/2023 |
1.0.21-alpha | 115 | 3/31/2023 |
1.0.20-alpha | 127 | 3/31/2023 |
1.0.19-alpha | 102 | 3/30/2023 |
1.0.18-alpha | 126 | 3/30/2023 |
1.0.17-alpha | 128 | 3/30/2023 |
1.0.15-alpha | 106 | 3/30/2023 |
1.0.14-alpha | 110 | 3/30/2023 |
1.0.13-alpha | 133 | 3/29/2023 |
1.0.12-alpha | 115 | 3/29/2023 |
1.0.10-alpha | 143 | 3/28/2023 |
1.0.9-alpha | 112 | 3/28/2023 |
1.0.4-alpha | 123 | 3/27/2023 |
1.0.3-alpha | 135 | 3/27/2023 |
1.0.2-alpha | 116 | 3/27/2023 |
1.0.0 | 89 | 6/30/2023 |