Debian Codegraph @

www/src/content/reference/05-methods/09-htmx-registerExtension.md

raw symbols SCIP
1 ---
2 title: "htmx.registerExtension()"
3 description: "Register htmx extension"
4 ---
5
6 Registers an htmx extension. Alias for `htmx.defineExtension()`.
7
8 ## Syntax
9
10 ```javascript
11 htmx.registerExtension(name, extension)
12 ```
13
14 ## Parameters
15
16 - `name` - String name for the extension
17 - `extension` - Extension object with hook methods
18
19 ## Usage
20
21 ```javascript
22 htmx.registerExtension('my-ext', {
23 init: function(api) {
24 // Called when extension is registered
25 },
26 onEvent: function(name, evt) {
27 // Called for htmx events
28 }
29 });
30 ```
31
32 ## Extension Methods
33
34 Extensions can implement these hook methods:
35
36 - `init(api)` - Called when extension registers
37 - `onEvent(name, evt)` - Called for htmx events
38 - `transformResponse(text, xhr, elt)` - Modify response before processing
39 - `isInlineSwap(swapStyle)` - Return true if custom swap style should be processed
40 - `handleSwap(swapStyle, target, fragment, settleInfo)` - Handle custom swap styles
41 - `encodeParameters(xhr, parameters, elt)` - Modify request parameters
42
43 ## Notes
44
45 * Same as `htmx.defineExtension()` - both names work
46 * Extension must be in `htmx.config.extensions` list to load (unless list is empty)
47 * Extensions are only registered once (duplicate registrations ignored)
48 * `init` method receives internal API for advanced integrations