Function fromMustacheTemplate

  • Render a Mustache template into a container

    Type Parameters

    Parameters

    • template: string

      Mustache template

    • Optional options: Options

      Options object.

    Returns ((container, state) => Promise<undefined>)

    Render function

      • (container, state): Promise<undefined>
      • Parameters

        • container: HTMLElement
        • state: State

        Returns Promise<undefined>

    Example

    import { fromMustacheTemplate } from "@nosto/autocomplete/mustache";

    const render = fromMustacheTemplate(`
    <div>
    <h1>{{title}}</h1>
    <ul>
    {{#products}}
    <li>{{name}}</li>
    {{/products}}
    </ul>
    </div>
    `, {
    helpers: {
    toJson: function () {
    return JSON.stringify(this)
    }});

    render(document.getElementById("container"), {
    title: "My Title",
    products: [
    { name: "Product 1" },
    { name: "Product 2" },
    { name: "Product 3" }
    ]
    });

Generated using TypeDoc