BaseTagHelpers 0.1.1
dotnet add package BaseTagHelpers --version 0.1.1
NuGet\Install-Package BaseTagHelpers -Version 0.1.1
<PackageReference Include="BaseTagHelpers" Version="0.1.1" />
paket add BaseTagHelpers --version 0.1.1
#r "nuget: BaseTagHelpers, 0.1.1"
// Install BaseTagHelpers as a Cake Addin #addin nuget:?package=BaseTagHelpers&version=0.1.1 // Install BaseTagHelpers as a Cake Tool #tool nuget:?package=BaseTagHelpers&version=0.1.1
BaseTagHelpers
BaseTagHelpers is a collection of ASP.NET Core Tag Helper base classes to create Tag Helpers from.
Installation
You can install the package via NuGet:
dotnet add package BaseTagHelpers
Usage
RazorTagHelperBase without Child Content
The RazorTagHelperBase
class is a base class for creating Tag Helpers that render Razor content.
public record MyTagHelperModel(string FirstName, string LastName);
MyRazorTagHelper : RazorTagHelperBase
{
[HtmlAttributeName("model")] public MyTagHelperModel? Model { get; set; }
public MyRazorTagHelper(
IHtmlHelper htmlHelper
) : base(htmlHelper)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
SetPartialName(
"MyRazorTagHelper.cshtml",
Model
);
await base.ProcessAsync(context, output);
}
}
@model MyTagHelperModel
<div>
<h1>Hello @Model.FirstName @Model.LastName</h1>
</div>
RazorTagHelperBase with Child Content
public class MyTagHelperModel : IHasChildContent
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string? ChildContent { get; set; }
}
MyRazorTagHelper : RazorTagHelperBase
{
[HtmlAttributeName("model")] public MyTagHelperModel? Model { get; set; }
public MyRazorTagHelper(
IHtmlHelper htmlHelper
) : base(htmlHelper)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
SetPartialName(
"MyRazorTagHelper.cshtml",
Model,
true // Set to true to allow child content
);
await base.ProcessAsync(context, output);
}
}
@model MyTagHelperModel
<div>
<h1>Hello @Model.FirstName @Model.LastName</h1>
</div>
<div>
@Html.Raw(@Model.ChildContent)
</div>
ChildContentRazorTagHelperBase
The ChildContentRazorTagHelperBase
class is a base class for creating Tag Helpers that render child content without having a model.
MyChildContentTagHelper : ChildContentRazorTagHelperBase
{
public MyChildContentTagHelper(
IHtmlHelper htmlHelper
) : base(htmlHelper)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
SetPartialName(
"MyChildContentTagHelper.cshtml"
);
await base.ProcessAsync(context, output);
}
}
@model string
<div>
@Html.Raw(@Model)
</div>
Want to contribute?
This project is just getting off the ground and could use some help with cleaning things up and refactoring.
If you want to contribute - we'd love it! Just open an issue to work against so you get full credit for your fork. You can open the issue first so we can discuss and you can work your fork as we go along.
If you see a bug, please be so kind as to show how it's failing, and we'll do our best to get it fixed quickly.
Before sending a PR, please create an issue to introduce your idea and have a reference for your PR.
We're using conventional commits, so please use it for your commits as well.
Discussions
If you want to discuss an BaseTagHelpers
issue or PR in more detail, feel free to start a discussion.
You can also join our Discord server to discuss the project.
License
The MIT License (MIT). Please see License File for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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 is compatible. 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. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.26)
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.15)
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
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 |
---|---|---|
0.1.1 | 153 | 2/26/2024 |
0.1.0 | 129 | 2/26/2024 |
0.0.0-alpha.0 | 63 | 2/26/2024 |