Skip to content

Template partials/fragments #128

Description

@wrapperup

Hi, I've been toying around with ructe and htmx (it's great!), and one feature that would be great to see is the ability to render a fragment or part of a template. This is great in the context of htmx, where you re-render a small part of a template. Some reading: https://htmx.org/essays/template-fragments/

Prior art:

  1. https://github.com/sponsfreixes/jinja2-fragments
  2. Minijinja just merged this feature in Feature: Render Block fragment mitsuhiko/minijinja#260,

My quick sketch is something like

@(param: Type, ...)

<body>
    @fragment name(param: Type, ...) {
        <p>Hello @param!</p>
    }
</body>

Since parameters are defined in the template, it probably(?) makes sense that it must be a subset of the parameters in the main template. A new module would be created with the parent template's name and the name of the fragment I'd imagine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions