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

Fragments [Feature Request] #90

Closed
librasteve opened this issue Nov 16, 2024 · 1 comment
Closed

Fragments [Feature Request] #90

librasteve opened this issue Nov 16, 2024 · 1 comment

Comments

@librasteve
Copy link
Contributor

librasteve commented Nov 16, 2024

According to the author of HTMX (Carson Gross)

Template fragments are a relatively rare Server Side Rendering (SSR) template library feature that allow you to render a fragment or partial bit of the content within a template, rather than the entire template. This feature is very handy in Hypermedia Driven Applications because it allows you to decompose a particular view for partial updates internally without pulling fragments of the template out to separate files for rendering, creating a large number of individual template files.

By keeping all the HTML in a single file, it is also easier to reason about how a feature works. This follows the Locality of Behavior design principle.

https://htmx.org/essays/template-fragments/

Here is the example he presents:

<html>
    <body>
        <div hx-target="this">
          #if contact.archived
          <button hx-patch="/contacts/${contact.id}/unarchive">Unarchive</button>
          #else
          <button hx-delete="/contacts/${contact.id}">Archive</button>
          #end
        </div>
        <h3>Contact</h3>
        <p>${contact.email}</p>
    </body>
</html>

There is a list of those template engines that do have fragments support at the bottom of the page.


I am a big advocate of LOB in web design and feel that my raku HTMX examples would be cleaner and more maintainable (as would any HTMX site using Cro) if Cro had Fragments.

@librasteve
Copy link
Contributor Author

Feature merged via
#91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant