A quick install template solution to develop and deploy .NET application using GC Design System (GCDS). Currently designed for MVC & Razor projects.
-
Download the
GCDS.NetTemplatefrom Nuget.org into an .NET 8 or later MVC project -
Add the required services to your application in your
Program.csenabling the dependency injection of the template to workbuilder.AddMvcTemplateServices(); // for MVC projects builder.AddRazorTemplateServices(); // for Razor projects
-
Ensure your view points one of the provided Layouts:
GCDS.NetTemplate/_Layoutdefault layout for most pagesGCDS.NetTemplate/_Layout.SideNavcustomized layout when using theSideNavpropertyGCDS.NetTemplate/_Layout.Splashcustom layout for use specifically with theSplashtemplate, see bellow for more info
By default, the Basic template will be loaded, and it will resemble the Basic template from GCDS.
Note: Even if a template is loaded, you don't have to use it. It only gets used if you are using one of the provided layouts.
Option 1. Set a default template type globally in the Program.cs.
builder.Services.AddMvcTemplateServices(typeof(InternalApp)) // for MVC projects
builder.Services.AddRazorTemplateServices(typeof(InternalApp)) // for Razor projectsOption 2. Use a different template for a controller, page or action by applying a TemplateType attribute. This Will take precedence over other defaults.
[TemplateType(typeof(InternalApp))]
public IActionResult Index() // public class IndexModel : PageModelOption 3. (MVC only) Use the template on only some controllers by not registering the service globally in the Program.cs and adding a ServiceFilter to the controller that should use it.
// Program.cs
builder.Services.AddMvcTemplateServices(global: false)
// Controller
[ServiceFilter(typeof(TemplateActionFilter))]
public class HomeController : ControllerIt's recommended to use the Initialize function on this template to set the required properties. This function is chainable to access other properties.
template.Initialize("My Application Title");
// OR
template.Initialize(new ExtSiteTitle { Text = "Home", Href = "#" })
.HeadElements.AddMeta("name", "content");You can still self initialize the required props. When doing so you can access the LangToggleHref built by the template instead of creating that yourself.
template.Header = new ExtAppHeader
{
AppHeaderTop = new ExtAppHeaderTop
{
LanguageToggle = new GcdsLangToggle { Href = template.LangToggleHref },
SiteTitle = new ExtSiteTitle
{
Text = "My Application",
Href = Url.Action("Index")
},
}
}Remember to Initialize the template!
template.Initialize("Page Name", new ExtLanguageSelector("Custom Splash Title", "Titre d'éclaboussure personnalisé", Url.Action("Home")));By default, the splash page will load in either, english or french first depending on the current culture. This could be nice if you want it to respond to the last language that was used for the site. However if you need it to stick to one language, ensure to force the culture when loading the page.
HttpContext.SetTemplateCulture(CommonConstants.ENGLISH_CULTURE);_Reminder: Be sure to use the GCDS.NetTemplate/_Layout.Splash when using this template
Available on the Basic and Internal template.
Steps to use
-
Target the left menu layout variant
Layout = "GCDS.NetTemplate/_Layout.SideNav";
-
Set the
SideNavproperty of your template has with eitherGcdsSideNavorCustomPartialtemplate.SideNav = new GcdsSideNav { Label = "Left Nav", Links = [ new GcdsNavLink { Text = new HtmlString("Link 1"), Href = "#" }, new GcdsNavGroup { Label = "Group 1", Links = [ new GcdsNavLink("#", "Link 1.1"), new GcdsNavLink("#", "Link 1.2") ] }, new GcdsNavLink ("#", "Link 2") ], StyleOverride = "background-color: #e1e4e7;" }; // OR template.SideNav = new CustomPartial() { ViewName = "Banner", Model = new Banner { Text = "This is my custom menu" } };
-
(Optional) Add
PreContentsection in your view, to come before the left menu, and wrap everything in themaintag@section PreContent { <h1>Page H1 can go here</h1> } -
(Optional) Add
PostContentsection in your view, to come after the left menu and main body@section PostContent { <p>Other pre-footer content can go here</p> <p>Will be after the `main` tag if PreContent is not provided</p> }
In your page or controller, access the template to manipulate it to your needs.
This is how you can edit the breadcrumbs, menu, footer links, or override features like the language toggle. The Initialize function will prompt you to add required fields.
var template = ViewData.GetTemplate<InternalApp>();
template.Initialize(...)Since most sites work better with meta data, be sure to add some through the HeadElements. You can also add links to scripts and style pages, or any kind of head element you wish.
template.HeadElements.AddMeta("description", "This is a custom splash page for testing purposes.");
template.HeadElements.AddStyle("p { font-size: 20px; }");
template.HeadElements.AddLink("https://www.google.ca/css/style.css");
template.HeadElements.AddScript("www.google.ca");
template.HeadElements.AddCustom("tag", new Dictionary<string, string> { { "tagAttribute", "value" } }, "innerHtml");Note: Head and Script sections are also available on all templates.
While everything can be adjusted server side in code, sometimes the view needs to also adjust template settings and values.
Adjust the breadcrumbs, and the browser's Page title
ViewBag.PageTitle = "Home Page"; // should use a localizer here
ViewBag.Breadcrumbs = new List<GcdsLink> {
new("#", "Go back") // should use a Url.Action here
};How they are used can also be modified with the following attributes: (the default is "Replace")
public enum ViewDataAction { Replace, Prepend, Append }
template.PageTitleAction = TemplateBase.ViewDataAction.Append;
template.Header.Breadcrumbs.ItemsAction = TemplateBase.ViewDataAction.Prepend;Will default to 320px the property will accept text so any %, px, em, ext. will work.
ViewBag.SideNavWidth = "20%";Must be used on the SideNav layout
Will render on all templates (except Splash)
This will render a identifier text bellow the DateModified
ViewBag.PageIdentifier = "CND-1";Add configuration values to your appsettings.json to override from the defaults (shown in comments)
"TemplateSettings": {
"GcdsRootPath": "https://cdn.design-system.alpha.canada.ca/",
"GcdsComponentsVersion": "latest",
"GcdsComponentsStylePath": "@gcds-core/components@{0}/dist/gcds/gcds.css",
"GcdsComponentsModulePath": "@gcds-core/components@{0}/dist/gcds/gcds.esm.js",
"GcdsCssShortcutsPath": "@gcds-core/css-shortcuts@latest/dist/gcds-css-shortcuts.min.css"
"SplashLoadsDefaultBackgroundImage": true
}GcdsComponentsVersion will be injected into {0}.
GcdsCssShortcutsPath has a distinct version it uses directly only.
Leverage the component partials to build your own templates and features within your page. Provided partials & matching component classes: (linked to GCDS matching component if available)
Note: Most GCDS components can be used natively within the view so are not built as a partial
- GCDS components
GcdsBreadcrumbsGcdsDateModifiedGcdsFooterGcdsHeaderGcdsLangToggle(Language Toogle)GcdsLinkGcdsNavGroup: A sub-component used in theGcdsTopNavGcdsNavLink: A sub-component used inGcdsTopNavandGcdsNavGroupGcdsSearchGcdsSignatureGcdsTopicMenu(Theme and topic menu)GcdsTopNav(Top navigation)GcdsSideNav(Left Menu)
- Custom components
ExtAppHeader: Header for theInternalApptemplateExtAppHeaderTop: A top section for theExtAppHeaderExtHeadSettings: ImplementsTemplateSettingsfor a<head>sectionExtHtmlElement: Enables the rendering of a fully customized html element, used forHeadElements(meta tags)ExtLanguageSelector: A grid that has english and french links with titles for both, used in theSplashtemplateExtRandomBackground: Will randomize a full screen background image base on a set of image paths, used in theSplashtemplateExtSiteTitle: Title (link) for theExtAppHeaderTopExtSkipTo: Custom hidden link to skip to a section, used in theInternalApptemplateExtPageIdentifier: Identify the page by a unique string provided via ViewData
- Other Partials
SlotHeader: Helper to swap theGcdsHeaderor theExtAppHeaderfor the common layoutSlotHeaderMenu: Helper to swap theGcdsTopicMenuor theGcdsTopNavorCustomPartialfor theGcdsHeader.MenuandExtAppHeader.MenuSlotNavLinks: Helper to iterate over aIEnumerable<ISlotNavLink>to swap theGcdsNavLinkand theGcdsNavGroupfor theGcdsSideNav.LinksandGcdsTopNav.Links.SlotSideNav: Helper to swap theGcdsSideNavor theCustomPartialfor the Side Menu template variants.CustomPartial: Enables providing a partial name, model, and view data, to load a fully custom partial.
Use the built-in Translation by adding additional configurations to your Program.cs
builder.Services.ConfigureTemplateCulture();
app.UseRequestLocalization(); // part of .NETAnyone can create Issues (Bugs, Feature Requests, Suggestions)
You must be GC employee to contribute. Fork and make a pull request with signed commits.
It's using .NET 8, Visual Studio or VSCode should work.
Use the Sanity project to run and validate changes locally, as these a files that should not be released in the package.