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

Improve client-side-templates Extension to Handle Mustache Partials #122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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>

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