htmx-extensions icon indicating copy to clipboard operation
htmx-extensions copied to clipboard

Adding head support to the html tag

Open fullstackplus opened this issue 1 year ago • 2 comments

Due to the way my markup is structured, I have multiple HTML (ERB) templates starting with the body tag. So instead of adding hx-ext="head-support" on each and every one of them, I want to put it on the html tag which is declared once in my global layout file.

Will this work? I've been searching the docs but all examples use the body tag for hx-ext / hx-boost.

fullstackplus avatar Sep 27 '24 10:09 fullstackplus

This issue should be closed. An HTML document is supposed to have only one HTML tag. The user is asking for support to an edge case that shouldn't exist in the first place.

@fullstackplus is asking if they can add the hx-ext="head-support" attribute once to the <html> element in the root layout instead of having to add it to the <body> element in each of their HTML template files. They are not declaring multiple <html> tags per document.

Regarding the original question, I think you can add the attribute to the <html> element, given the following quote from the "Attribute Inheritance" section of the HTMX documentation:

Most attributes in htmx are inherited: they apply to the element they are on as well as any children elements. This allows you to “hoist” attributes up the DOM to avoid code duplication.

In case adding the attribute to the <html> element does not work, maybe you can try moving the <body> element declaration into the layout file and add the attribute there (meaning your template file would no longer require you to re-declare the <body> element).

Hope this helps.

lubeso avatar Apr 25 '25 10:04 lubeso