https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • r

    ripe-action-67367

    03/09/2023, 2:40 PM
    Copy code
    html
    <div id="outer">
      <div id="inner"></div>
    </div>
    basically, you can set hx-select="#inner" and htmx will find it in the body and trim out #outer
  • r

    ripe-action-67367

    03/09/2023, 2:41 PM
    It's useful, when you don't have dedicated endpoints for fragment responses. You can load full page and only select part of it for swap
  • r

    ripe-action-67367

    03/09/2023, 2:43 PM
    As for this, mixing html and json in the same endpoint is very tricky. Usually, JSON apis have some requirements, that are not relevant for html endpoints, such as versioning. Consider putting JSON API into separate routes, like
    api/v1/posts
    or something
  • s

    shy-knife-59740

    03/09/2023, 2:52 PM
    thanks a lot
  • s

    shy-knife-59740

    03/09/2023, 2:53 PM
    i dont plan on having more endpoints tbh, its a small CMS like thing that uses python-markdown
  • s

    shy-knife-59740

    03/09/2023, 2:53 PM
    but ill keep that in mind
  • r

    ripe-action-67367

    03/09/2023, 2:54 PM
    That's obviously not critical in any way
  • r

    ripe-action-67367

    03/09/2023, 2:54 PM
    Do what makes the most sense
  • s

    shy-knife-59740

    03/09/2023, 2:56 PM
    would it be better (and possible) to replace that div element itself?
    r
    • 2
    • 21
  • s

    some-airline-73512

    03/09/2023, 4:18 PM
    Anyone used https://github.com/mojolicious/mojo.js ? I'm reading the website and it seems solid and very simple. Should be good for hypermedia-driven apps
  • s

    some-airline-73512

    03/09/2023, 4:20 PM
    I'm pretty satisfied with the current Restana server. But I'm always open for something that could boost productivity. Retaining simplicity and control over codebase is a priority here
  • s

    some-airline-73512

    03/09/2023, 4:23 PM
    HN discussion https://news.ycombinator.com/item?id=33656829
  • h

    happy-knife-63802

    03/09/2023, 10:37 PM
    have you tried using hx-preserve to prevent the element from being updated subsequently?
  • h

    happy-knife-63802

    03/09/2023, 10:41 PM
    that’s usually a good solution. you can target the div and swap the outerhtml. if you don’t have an endpoint specific for the fragment you can use hx-select to grab the div element from the endpoint that returns the whole page
  • s

    shy-knife-59740

    03/09/2023, 10:41 PM
    I fixed it already, it was an issue on how i was loading my jinja templates
  • s

    shy-knife-59740

    03/09/2023, 10:41 PM
    But thanks
  • h

    happy-knife-63802

    03/09/2023, 10:41 PM
    👍
  • s

    shy-knife-59740

    03/09/2023, 10:43 PM
    Basically the route i was running the htmx part from used "base.html" and the route i made the request to returned a jinja template that already extended base.html
  • h

    happy-knife-63802

    03/09/2023, 10:45 PM
    hx-select would have done the job then
  • l

    limited-teacher-83117

    03/10/2023, 3:03 AM
    I got a support request for my HTMX app once that was just scrolling down this for 14 seconds
  • g

    gorgeous-ghost-95789

    03/10/2023, 3:04 AM
    ooohh, fun! The ol' infinite loop include...
  • l

    limited-teacher-83117

    03/10/2023, 3:05 AM
    It was because before I started templating everything, I had an
    hx-trigger=load
    that would load the main content of the app. I forgot that one of the pages still operated that way when I switched it over to the template, so it just kept calling itself
  • l

    limited-teacher-83117

    03/10/2023, 3:06 AM
    Anyhow: hard links, full page reloads, wide targets—this is the way
  • h

    hundreds-cartoon-20446

    03/10/2023, 12:32 PM
    In case anyone is using it, I updated my
    hx-history-preserve
    extension to be a little more robust. It now also caches the original markup of any fragments swapped into the current page (not just full pages with an
    hx-history-elt
    element), and restores them to a pristine state before the page is saved to the history cache. That can be extremely useful when you need to (re)initialise javascript behaviour attached to dom elements on browser back/forward navigation. https://gist.github.com/croxton/e2c33bd22591f9a5bd8c9d23a56c9edc
  • w

    wonderful-article-82635

    03/10/2023, 2:27 PM
    Can HTMX swap text without issuing a request? For example, in the code below, can the user click on one of the list items and have the value "one" or "two" show up in the div?
    Copy code
    <div>value gets put here</div>
    <ul>
      <li>one</li>
      <li>two</li>
    </ul>
  • g

    gentle-salesclerk-37089

    03/10/2023, 2:32 PM
    thats not really what htmx do
  • g

    gentle-salesclerk-37089

    03/10/2023, 2:32 PM
    you can use htmx with something like alpine js to keep it all in the dom though
  • w

    wonderful-article-82635

    03/10/2023, 2:49 PM
    Got it, thanks!
  • g

    gentle-salesclerk-37089

    03/10/2023, 2:50 PM
    htmx + alpine + tailwind is a solid combo
  • b

    big-airline-13935

    03/10/2023, 4:02 PM
    Check out https://hyperscript.org/.
1...106310641065...1146Latest