Table of Contents

Class HtmxToolkitOptions

Namespace
Ramstack.HtmxToolkit.Configuration
Assembly
Ramstack.HtmxToolkit.dll

Represents configuration options for services provided by HTMX Toolkit.

public sealed class HtmxToolkitOptions
Inheritance
HtmxToolkitOptions
Inherited Members

Examples

using Ramstack.HtmxToolkit.Hosting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();

// HTMX 2.x is the default. 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

HtmxConfig

Remarks

If no version has been explicitly configured, this property defaults to HTMX 2.x.

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

bool

TargetVersion

Gets the HTMX major version used for version-sensitive generated markup.

public HtmxTargetVersion TargetVersion { get; }

Property Value

HtmxTargetVersion

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

TConfig

The expected configuration type.

Exceptions

InvalidOperationException

TConfig does not match the selected HTMX major version.

UseHtmxV1(Action<HtmxV1Config>?)

Selects and configures HTMX 1.x.

[MemberNotNull("_config")]
public HtmxToolkitOptions UseHtmxV1(Action<HtmxV1Config>? configure = null)

Parameters

configure Action<HtmxV1Config>

The optional delegate used to configure HTMX 1.x.

Returns

HtmxToolkitOptions

The current options instance.

Exceptions

InvalidOperationException

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

configure Action<HtmxV2Config>

The optional delegate used to configure HTMX 2.x.

Returns

HtmxToolkitOptions

The current options instance.

Exceptions

InvalidOperationException

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

configure Action<HtmxV4Config>

The optional delegate used to configure HTMX 4.x.

Returns

HtmxToolkitOptions

The current options instance.

Exceptions

InvalidOperationException

A different HTMX major version has already been selected.