emmett-framework / emmett

The web framework for inventors
Other
1.03k stars 70 forks source link

Suggestion: Snippet response support, helps with HTMX #492

Open gaytomycode opened 2 months ago

gaytomycode commented 2 months ago

I am playing around with Emmett on a couple of production products and i use htmx a lot. i found a solution around to response with html snippets and i can add support for it in the framework if it's a good idea.

image

i also want to add things like an htmx extension that adds full htmx support to make using htmx easy with Emmett as well as the ability to respond with a fragment of the template file like django-template-partials or jinja2-fragments. let me know guys if this is interesting i am happy to work on it.

gi0baro commented 2 months ago

@gaytomycode this looks like a good addition to response types. I'm wondering if it would be better to return a tuple from the route in the form (snippet, context), so you can also inject variables. Eg based on your code:

async def hello_htmx():
    return "<h1>Hello, {{ =name }}</h1>", {"name": "HTML Snippet"}

Using context will also make injectors work also with snippets if needed.

gaytomycode commented 2 months ago

@gi0baro thank you for your reply. your suggestion makes sense will include it. glad you think it's a good addition will work on it. :)