Class HtmxHeaderTagHelper
- Namespace
- Ramstack.HtmxToolkit.TagHelpers
- Assembly
- Ramstack.HtmxToolkit.dll
Applies an hx-headers attribute assembled from strongly typed tag helper attributes.
[HtmlTargetElement(Attributes = "hx-headers-inherited")]
[HtmlTargetElement(Attributes = "hx-headers-append")]
[HtmlTargetElement(Attributes = "hx-all-headers")]
[HtmlTargetElement(Attributes = "hx-header-*")]
public sealed class HtmxHeaderTagHelper : TagHelper, ITagHelper, ITagHelperComponent
- Inheritance
-
HtmxHeaderTagHelper
- Implements
- Inherited Members
Examples
@addTagHelper *, Ramstack.HtmxToolkit
<section hx-header-X-Tenant="@Model.TenantId">
<button hx-get="/reports" hx-target="#report">Load report</button>
</section>
@* Renders hx-headers='{"X-Tenant":"..."}' with the JSON built and escaped for you. *@
Remarks
- HTMX 1.x and 2.x merge-inherit
hx-headersfrom parent elements. - HTMX 4.x requires either the explicit inheritance modifier or the global ImplicitInheritance option for inheritance.
- The
appendmodifier merges a child declaration into inherited headers.
Constructors
HtmxHeaderTagHelper(IOptions<HtmxToolkitOptions>)
Applies an hx-headers attribute assembled from strongly typed tag helper attributes.
public HtmxHeaderTagHelper(IOptions<HtmxToolkitOptions> options)
Parameters
optionsIOptions<HtmxToolkitOptions>
Remarks
- HTMX 1.x and 2.x merge-inherit
hx-headersfrom parent elements. - HTMX 4.x requires either the explicit inheritance modifier or the global ImplicitInheritance option for inheritance.
- The
appendmodifier merges a child declaration into inherited headers.
Properties
Append
Gets or sets a value indicating whether hx-headers is appended to inherited headers.
[HtmlAttributeName("hx-headers-append")]
public bool Append { get; set; }
Property Value
Remarks
HTMX 4.x emits the append modifier when this property is true.
The property does not change the generated attribute name for HTMX 1.x and 2.x.
Headers
Gets or sets the hx-headers attribute values.
[HtmlAttributeName("hx-all-headers", DictionaryAttributePrefix = "hx-header-")]
public IDictionary<string, string> Headers { get; set; }
Property Value
Inherited
Gets or sets a value indicating whether hx-headers is explicitly inherited.
[HtmlAttributeName("hx-headers-inherited")]
public bool Inherited { get; set; }
Property Value
Remarks
HTMX 1.x and 2.x merge-inherit headers without a modifier.
HTMX 4.x emits the inherited modifier when this property is true.
Methods
ProcessAsync(TagHelperContext, TagHelperOutput)
Asynchronously executes the TagHelper with the given context and
output.
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
Parameters
contextTagHelperContextContains information associated with the current HTML tag.
outputTagHelperOutputA stateful HTML element used to generate an HTML tag.
Returns
Remarks
By default this calls into Process(TagHelperContext, TagHelperOutput).