yiisoft / html

Handy library to generate HTML
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
53 stars 17 forks source link

HTMX support? #186

Open razvanphp opened 5 months ago

razvanphp commented 5 months ago

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

samdark commented 5 months ago

What's required for it from the framework side?

razvanphp commented 5 months ago

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.

samdark commented 5 months ago

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

xepozz commented 5 months ago

Add it as a asset to your template

  <script src="https://unpkg.com/htmx.org@1.9.10"></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 commented 5 months ago

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

razvanphp commented 5 months ago

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.

vjik commented 5 months ago

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.

samdark commented 5 months ago

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