Function fromMustacheTemplate

  • Render a Mustache template into a container

    Type Parameters

    Parameters

    • template: string

      Mustache template

    • Optionaloptions: Options

      Options object.

    Returns ((container: HTMLElement, state: State) => Promise<undefined>)

    Render function

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

        • container: HTMLElement
        • state: State

        Returns Promise<undefined>

    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" }
    ]
    });