Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Neapolitan with HTMX #33

Open
Yacobolo opened this issue Nov 15, 2023 · 2 comments
Open

Using Neapolitan with HTMX #33

Yacobolo opened this issue Nov 15, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Yacobolo
Copy link

Hey Carlton - any suggestions on how to integrate this with htmx, or should i consider a different approach?

@carltongibson
Copy link
Owner

Hi @Yacobolo 👋

So... the first take would be Just use it! 😅 HTMX works great with Neapolitan. I'm using it myself daily, and I highly recommend it.

I guess, the Tip would be to (first-pass) use hx-select to pick just a part of the response to swap-in, and then (bit more advanced) set self.template_name in the view (or overriding get_template_names()) to specify an HTMX specific template.

I created my package django-template-partials in order to aid this second use case. You can define your partials in your main template and then reference them by name later on. I'd recommend checking that out.

As I say, I'm using this daily. I find the combination of Neapolitan's CRUDView, django-template-partials, and HTMX to be really powerful. It gives me pretty much everything I want. I add a sprinkle of JS using Alpine.js, and that's about it. I'm not finding that I need to reach for much more.

I hope that helps?

Links:

  1. https://htmx.org/attributes/hx-select/
  2. https://github.com/carltongibson/django-template-partials
  3. https://alpinejs.dev

@carltongibson carltongibson changed the title Usage with HTMX Using Neapolitan with HTMX Nov 15, 2023
@carltongibson carltongibson pinned this issue Nov 15, 2023
@jefftriplett
Copy link

django-htmx might be worth a mention too. I have been using it with neapolitan + django-template-partials along with this pattern. (pulled this snippet from a production website)

    def get_template_name(self):
        template_name = "jobs/joblisting_list.html"

        if self.request.htmx:
            template_name = f"{template_name}#job-list-partial"

        return template_name

@carltongibson carltongibson added the documentation Improvements or additions to documentation label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants