htmx-extensions
htmx-extensions copied to clipboard
Improve client-side-templates Extension to Handle Mustache Partials
Description
This pull request enhances the client-side-templates extension for HTMX by addressing an issue with Mustache partials in strict HTML contexts, such as
elements in tables. Due to HTML parsing rules, Mustache expressions must often be wrapped in comment tags () to ensure valid HTML. This update automatically removes those comment tags after rendering, simplifying the integration of Mustache partials.Htmx version: 2.0.2
Changes New Behavior:
Automatically strips HTML comment tags () from rendered content while preserving the Mustache-generated output. Provides seamless support for Mustache partials within strict HTML elements like
.Testing
<template id="table-template">
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<!-- {{#items}} -->
<!-- {{> row-template}} -->
<!-- {{/items}} -->
</tbody>
</table>
</template>
<template id="row-template">
<tr>
<td>{{value1}}</td>
<td>{{value2}}</td>
</tr>
</template>
<div
id="table-container"
hx-get="/api/data"
hx-trigger="load"
hx-target="#table-container"
hx-swap="innerHTML"
hx-ext="client-side-templates-hal"
mustache-hal-template="table-template">
</div>
Deploy Preview for htmx-extensions canceled.
| Name | Link |
|---|---|
| Latest commit | 972ef0a20a5a3ca8eae84d2e1d9e18bc4f9ef2d8 |
| Latest deploy log | https://app.netlify.com/sites/htmx-extensions/deploys/675b64e3d7b0750008bae8b6 |