Class HtmxToolkitOptions
- Namespace
- Ramstack.HtmxToolkit.Configuration
- Assembly
- Ramstack.HtmxToolkit.dll
Represents configuration options for services provided by HtmxToolkit.
public sealed class HtmxToolkitOptions
- Inheritance
-
HtmxToolkitOptions
- Inherited Members
Examples
using Ramstack.HtmxToolkit.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
// Select the version that your pages load, and set only
// the HTMX options that should differ from the HTMX defaults.
builder.Services.AddHtmxToolkit(options =>
{
options.UseHtmxV4(config =>
{
config.DefaultTimeout = 10_000;
});
});
Properties
HtmxConfig
Gets the configuration for the selected HTMX major version.
public HtmxConfig HtmxConfig { get; }
Property Value
Remarks
Throws InvalidOperationException if no version has been selected with UseHtmxV1(Action<HtmxV1Config>?), UseHtmxV2(Action<HtmxV2Config>?), or UseHtmxV4(Action<HtmxV4Config>?).
IncludeAntiforgeryToken
Gets or sets a value indicating whether antiforgery request metadata is rendered by the configuration tag helper. Defaults to true.
public bool IncludeAntiforgeryToken { get; set; }
Property Value
TargetVersion
Gets the HTMX major version used for version-sensitive generated markup and response headers.
public HtmxTargetVersion TargetVersion { get; }
Property Value
Remarks
For example, with HTMX 4.x, TriggerEvent(string, HtmxTriggerTiming)
emits events with any HtmxTriggerTiming value through the HX-Trigger header.
Throws InvalidOperationException if no version has been selected, as when reading HtmxConfig.
Methods
GetHtmxConfig<TConfig>()
Returns the selected version-specific HTMX configuration.
public TConfig GetHtmxConfig<TConfig>() where TConfig : HtmxConfig
Returns
- TConfig
The requested configuration instance.
Type Parameters
TConfigThe expected configuration type.
Remarks
Throws InvalidOperationException if no version has been selected,
or if the configuration of the selected version is not a TConfig.
UseHtmxV1(Action<HtmxV1Config>?)
Selects and configures HTMX 1.9.x.
[MemberNotNull("_config")]
public HtmxToolkitOptions UseHtmxV1(Action<HtmxV1Config>? configure = null)
Parameters
configureAction<HtmxV1Config>The optional delegate used to configure HTMX 1.9.x.
Returns
- HtmxToolkitOptions
The current options instance.
Remarks
Calling this method again reuses the existing configuration and applies the supplied delegate.
Throws InvalidOperationException if a different HTMX major version has already been selected.
UseHtmxV2(Action<HtmxV2Config>?)
Selects and configures HTMX 2.x.
[MemberNotNull("_config")]
public HtmxToolkitOptions UseHtmxV2(Action<HtmxV2Config>? configure = null)
Parameters
configureAction<HtmxV2Config>The optional delegate used to configure HTMX 2.x.
Returns
- HtmxToolkitOptions
The current options instance.
Remarks
Calling this method again reuses the existing configuration and applies the supplied delegate.
Throws InvalidOperationException if a different HTMX major version has already been selected.
UseHtmxV4(Action<HtmxV4Config>?)
Selects and configures HTMX 4.x.
[MemberNotNull("_config")]
public HtmxToolkitOptions UseHtmxV4(Action<HtmxV4Config>? configure = null)
Parameters
configureAction<HtmxV4Config>The optional delegate used to configure HTMX 4.x.
Returns
- HtmxToolkitOptions
The current options instance.
Remarks
Calling this method again reuses the existing configuration and applies the supplied delegate.
Throws InvalidOperationException if a different HTMX major version has already been selected.