Registers an htmx extension. Alias for htmx.defineExtension().
Syntax
htmx.registerExtension(name, extension)
Parameters
name- String name for the extensionextension- Extension object with hook methods
Usage
htmx.registerExtension('my-ext', { init: function(api) { // Called when extension is registered }, onEvent: function(name, evt) { // Called for htmx events } });
Extension Methods
Extensions can implement these hook methods:
init(api)- Called when extension registersonEvent(name, evt)- Called for htmx eventstransformResponse(text, xhr, elt)- Modify response before processingisInlineSwap(swapStyle)- Return true if custom swap style should be processedhandleSwap(swapStyle, target, fragment, settleInfo)- Handle custom swap stylesencodeParameters(xhr, parameters, elt)- Modify request parameters
Notes
- Same as
htmx.defineExtension()- both names work - Extension must be in
htmx.config.extensionslist to load (unless list is empty) - Extensions are only registered once (duplicate registrations ignored)
initmethod receives internal API for advanced integrations