Skip to content

Conversation

@dlemaignent
Copy link

@dlemaignent dlemaignent commented Dec 12, 2024

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>

@netlify
Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for htmx-extensions canceled.

Name Link
🔨 Latest commit 972ef0a
🔍 Latest deploy log https://app.netlify.com/sites/htmx-extensions/deploys/675b64e3d7b0750008bae8b6

@dlemaignent dlemaignent marked this pull request as ready for review December 12, 2024 22:35
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

Successfully merging this pull request may close these issues.

1 participant