Class HtmxConfigTagHelper
- Namespace
- Ramstack.HtmxToolkit.TagHelpers
- Assembly
- Ramstack.HtmxToolkit.dll
Renders the application-wide HTMX configuration as a <meta> element.
[HtmlTargetElement("meta", Attributes = "htmx-config", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("htmx-config", TagStructure = TagStructure.NormalOrSelfClosing)]
public sealed class HtmxConfigTagHelper : TagHelper, ITagHelper, ITagHelperComponent
- Inheritance
-
HtmxConfigTagHelper
- Implements
- Inherited Members
Examples
@addTagHelper *, Ramstack.HtmxToolkit
<head>
<htmx-config />
</head>
@* Renders the settings selected in AddHtmxToolkit and the antiforgery token
that the Toolkit script adds to HTMX requests:
<meta name="htmx-config" content='{"defaultTimeout":10000}'
data-antiforgery-request-token="..." ... /> *@
Remarks
The tag helper applies to both <htmx-config /> and
<meta htmx-config />.
When IncludeAntiforgeryToken is true,
the element also includes the antiforgery metadata that the Toolkit script
(htmx-toolkit.js) uses to send the token with HTMX requests.
Constructors
HtmxConfigTagHelper(IAntiforgery, IOptions<HtmxToolkitOptions>)
Renders the application-wide HTMX configuration as a <meta> element.
public HtmxConfigTagHelper(IAntiforgery antiforgery, IOptions<HtmxToolkitOptions> options)
Parameters
antiforgeryIAntiforgeryThe service used to generate antiforgery tokens.
optionsIOptions<HtmxToolkitOptions>The configured HtmxToolkit options.
Remarks
The tag helper applies to both <htmx-config /> and
<meta htmx-config />.
When IncludeAntiforgeryToken is true,
the element also includes the antiforgery metadata that the Toolkit script
(htmx-toolkit.js) uses to send the token with HTMX requests.
Properties
ViewContext
Gets or sets the view context for the current request.
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
Property Value
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).