Skip to main content

Stimulus

AddStimulus() discovers controllers from wwwroot/controllers/ (default) and registers them in the import map. No manual registration required.

Setup

using Tombatron.Turbo.Stimulus;

builder.Services.AddStimulus();

Naming Conventions

FileIdentifier
hello_controller.jshello
hello-controller.jshello
todo_form_controller.jstodo-form
todo-form-controller.jstodo-form
admin/users_controller.jsadmin--users
admin/user_settings_controller.jsadmin--user-settings

Both _controller.js and -controller.js suffixes are supported. Underscores become hyphens, the controller suffix is stripped, and directory separators become --.

Options

builder.Services.AddStimulus(options =>
{
options.ControllersPath = "js/controllers"; // Default: "controllers"
options.StimulusCdnUrl = "https://unpkg.com/..."; // Default: stimulus 3.2.2 from unpkg
options.EnableHotReload = true; // Default: auto-detect from environment
});

Hot Reload

Hot reload is enabled automatically in Development — save a controller file and the browser picks up the changes without a manual refresh.

Usage in HTML

Connect a controller to an element using data-controller:

<div data-controller="hello">
<input data-hello-target="name" type="text" />
<button data-action="click->hello#greet">Greet</button>
<span data-hello-target="output"></span>
</div>

For a complete example, see Step 8 of the Todo List tutorial.