Toolbelt.Blazor.HeadElement 1.0.0

Head element support (change the document title, "meta" elements such as OGP) for Blazor apps.

There is a newer version of this package available.
See the version list below for details.
Install-Package Toolbelt.Blazor.HeadElement -Version 1.0.0
dotnet add package Toolbelt.Blazor.HeadElement --version 1.0.0
<PackageReference Include="Toolbelt.Blazor.HeadElement" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.Blazor.HeadElement --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toolbelt.Blazor.HeadElement, 1.0.0"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

Blazor Head Element Helper NuGet Package

Summary

This components and services allows you to change the title of document and "meta" elements such as OGP, on your Blazor app.

This package supports both seiver-side Blazor and client-side Blazor WebAssembly app.

And also supports server-side pre-rendering on your server-side Blazor app.

How to use

Installation

  1. Add package to your project like this.
dotnet add package Toolbelt.Blazor.HeadElement
  1. Register "Head Element Helper" service at your Blazor app's Startup.
using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...

public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddHeadElementHelper(); // <- Add this.
    ...
  1. Open Toolbelt.Blazor.HeadElement namespace in _Imports.razor file.
@* This is "_Imports.razor" *@
...
@using Toolbelt.Blazor.HeadElement

A. Change the title of the document

  1. Markup <Title> component in your .razor file.
@* This is "Pages/Counter.razor" *@
@page "/counter"

<Title>Counter(@currentCount) - Server Side App</Title>

The title of document will be changed.

fig1

Note - IHeadElementHelper

You can do these tasks by using IHeadElementHelper service instead of using <Title> and <Meta> components.

You can get the IHeadElementHelper service instnace by "Dependency Injection" mechanism.

@inject IHeadElementHelper HeadElementHelper
@using static Toolbelt.Blazor.HeadElement.MetaElement
...
@code {
  protected override async Task OnInitializedAsync()
  {
    await HeadElementHelper.SetTitleAsync("Wow!");
    await HeadElementHelper.SetMetaElementsAsync(
      ByName("description", "Foo bar..."),
      ByProp("og:title", "WoW!")
    );
    ...

B. Change "meta" elements

You can also add or override "meta" elements at runtime dynamically using <Meta> component like this.

@* This is "Pages/Counter.razor" *@
@page "/counter"

<Meta Property="ogp:title" Content="Counter" />

C. Server-side pre-rendering support

If you want to get srever-side pre-rendering support, do this.

  1. Add Toolbelt.Blazor.HeadElement.ServerPrerendering package to your project like this.
dotnet add package Toolbelt.Blazor.HeadElement.ServerPrerendering
  1. Register "Head Element Server Prerendering" middleware at your server-side Blazor app's Startup, before app.UseStaticFiles().
using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...

public class Startup
{
  public void Configure(IApplicationBuilder app)
  {
    app.UseHeadElementServerPrerendering(); // <- Add this.
    ...
    app.UseStaticFiles()
    ...

fig2

License

Mozilla Public License Version 2.0

Blazor Head Element Helper NuGet Package

Summary

This components and services allows you to change the title of document and "meta" elements such as OGP, on your Blazor app.

This package supports both seiver-side Blazor and client-side Blazor WebAssembly app.

And also supports server-side pre-rendering on your server-side Blazor app.

How to use

Installation

  1. Add package to your project like this.
dotnet add package Toolbelt.Blazor.HeadElement
  1. Register "Head Element Helper" service at your Blazor app's Startup.
using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...

public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddHeadElementHelper(); // <- Add this.
    ...
  1. Open Toolbelt.Blazor.HeadElement namespace in _Imports.razor file.
@* This is "_Imports.razor" *@
...
@using Toolbelt.Blazor.HeadElement

A. Change the title of the document

  1. Markup <Title> component in your .razor file.
@* This is "Pages/Counter.razor" *@
@page "/counter"

<Title>Counter(@currentCount) - Server Side App</Title>

The title of document will be changed.

fig1

Note - IHeadElementHelper

You can do these tasks by using IHeadElementHelper service instead of using <Title> and <Meta> components.

You can get the IHeadElementHelper service instnace by "Dependency Injection" mechanism.

@inject IHeadElementHelper HeadElementHelper
@using static Toolbelt.Blazor.HeadElement.MetaElement
...
@code {
  protected override async Task OnInitializedAsync()
  {
    await HeadElementHelper.SetTitleAsync("Wow!");
    await HeadElementHelper.SetMetaElementsAsync(
      ByName("description", "Foo bar..."),
      ByProp("og:title", "WoW!")
    );
    ...

B. Change "meta" elements

You can also add or override "meta" elements at runtime dynamically using <Meta> component like this.

@* This is "Pages/Counter.razor" *@
@page "/counter"

<Meta Property="ogp:title" Content="Counter" />

C. Server-side pre-rendering support

If you want to get srever-side pre-rendering support, do this.

  1. Add Toolbelt.Blazor.HeadElement.ServerPrerendering package to your project like this.
dotnet add package Toolbelt.Blazor.HeadElement.ServerPrerendering
  1. Register "Head Element Server Prerendering" middleware at your server-side Blazor app's Startup, before app.UseStaticFiles().
using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...

public class Startup
{
  public void Configure(IApplicationBuilder app)
  {
    app.UseHeadElementServerPrerendering(); // <- Add this.
    ...
    app.UseStaticFiles()
    ...

fig2

License

Mozilla Public License Version 2.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Toolbelt.Blazor.HeadElement:

Repository Stars
Garderoben/MudBlazor
Blazor Component Library based on Material design. The goal is to do more with Blazor, utilizing CSS and keeping Javascript to a bare minimum.

Version History

Version Downloads Last updated
5.4.1 2,420 1/30/2021
5.4.0 1,204 1/10/2021
5.3.0 138 1/10/2021
5.2.0 155 1/10/2021
5.1.0 87 1/9/2021
5.0.0 5,912 11/10/2020
5.0.0-rc.1 875 9/7/2020
1.2.0 9,947 6/4/2020
1.2.0-beta 142 5/29/2020
1.1.1 1,649 4/16/2020
1.1.0.1 1,095 1/18/2020
1.0.0 634 11/1/2019
0.0.1-preview2.0.2 126 9/19/2019
0.0.1-preview1.0.1 127 9/12/2019
Show less