Support for modules in script #326
Replies: 2 comments 4 replies
-
I'm not really sure what the change is. You can already put a Can you write an example of the templ code you'd like to write, and the output HTML you'd like to see? |
Beta Was this translation helpful? Give feedback.
-
The simplified example could be this: package component
script ScriptForButtonWithTooltip(className string) {
import {computePosition} from 'https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]/+esm';
const button = document.querySelector(`${className} button`);
const tooltip = document.querySelector(`.${className} .tooltip`);
computePosition(button, tooltip).then(({x, y}) => {
Object.assign(tooltip.style, { left: `${x}px`, top: `${y}px` });
});
}
templ ButtonWithTooltip(id string) {
<div class={id}>
<button>Hover over me!</button>
<div class="tooltip">show me</div>
</div>
@ScriptForButtonWithTooltip(id)
}
// ... somewhere in the code
templ Page() {
@ButtonWithTooltip("id1")
@ButtonWithTooltip("id2")
@ButtonWithTooltip("id3")
@ButtonWithTooltip("id4")
} Currently, when using the
I am unsure if this kind of support is achievable or worth supporting, however, it would cover my use-case. |
Beta Was this translation helpful? Give feedback.
-
Modern browsers have started to support module functionality natively.
The syntax looks like this:
Currently, the templ supports text/javascript:
<script type="text/javascript">
.Can we extend templ, to be able to support such syntax?
(I am willing to help with the implementation if needed.)
Beta Was this translation helpful? Give feedback.
All reactions