html icon indicating copy to clipboard operation
html copied to clipboard

HTMX support?

Open razvanphp opened this issue 1 year ago • 8 comments

I've got on the HTMX boat recently (apparently with a big chunk of the industry) and I think it's a match made in heaven for Yii framework, considering the renderPartial functionality built-in.

Would a contribution with some helpers and first-class support be accepted?

I'm also thinking on putting it on yii2, given that Pjax is already there... we would revive the framework use-cases so easily given the excellent capabilities of Yii to generate HTML with GridView.

Cheers, R

razvanphp avatar Feb 10 '24 15:02 razvanphp

What's required for it from the framework side?

samdark avatar Feb 10 '24 16:02 samdark

The AssetBundle at least and was thinking about a widget/helper for Html/ActiveForm to create some of the attributes and links.

LE: I would also write some examples in the documentation so Yii appears in the search results caused by this hype.

razvanphp avatar Feb 10 '24 17:02 razvanphp

Hmm... I'd like that to be separated from Html/ActiveForm packages. A separate package would do.

samdark avatar Feb 10 '24 17:02 samdark

Add it as a asset to your template

  <script src="https://unpkg.com/[email protected]"></script>

Use the Button widget to generate htmx:

echo Button::tag()
            ->content('Click Me!')
            ->addAttributes([
                'hx-post' => '/clicked',
                'hx-swap' => 'outerHTML',
            ]);

Will generate the following:

<button hx-post="/clicked" hx-swap="outerHTML">
    Click Me
</button>

Didn't run it, but I hope it works this way

xepozz avatar Feb 10 '24 17:02 xepozz

It would be great if you provide some details about what you want have: shortcuts, styling, cross-widget referencing or whatever

xepozz avatar Feb 10 '24 17:02 xepozz

Hmm... I'd like that to be separated from Html/ActiveForm packages. A separate package would do.

… for Yii3 makes sense as all packages are independent, but for Yii2? It’s more about promoting the technology, I know I can add the attributes already.

razvanphp avatar Feb 10 '24 17:02 razvanphp

I think the best solution would be to create separate package (yiisoft/htmx) based on Yii HTML. We can create special classes for HTMX tags with methods, that will allow to add htmx-specific attributes. Also create HTMX widgets (if need).

@razvanphp If you feel the desire and opportunity enough do it, we help you with this.

vjik avatar Feb 11 '24 04:02 vjik

Yii2 core feature set is frozen. Creating extensions is OK though.

samdark avatar Feb 11 '24 08:02 samdark