Tmplits

Tmplits are JavaScript functions that are prefixed with the word tmplit followed by the name of the tmplit.

function TmplitMyCustomControl(context, args) can be referenced in a Partial using {{tmplit 'MyCustomControl'}}. Tmplits are used to create elements based on inputs. They are typically used to create custom controls that are parameterized, and can benefit from more complex logic.

Imagine you want a custom control that says new parameterized versions of “Hello World” and displays a count of days. You could create a tmplit that takes multiple parameters and returns the resulting HTML.

{{tmplit 'MyCustomControl' 'cruel' 'world' days='1' }}
{{tmplit 'MyCustomControl' 'cool' 'world' days='3' }}

To create the tmplit, define a function:

function TmplitMyCustomControl(context, args){
    //context: ['cruel', 'world']
    //args.hash: {days: '1'}

    //Read the days from the named arguments
    let {days} = args.hash;

    //Generate your custom components and return html
    let s = ""
    if(days > 1)
        s = 's'

    //Join the context array into a string separated by spaces
    let name = context.join(' ')

    //return the html
    return `    
<div>Hello ${name}</div>
<div>See you in ${day} day${s}.</div>
`
}

Output:

<div>Hello cruel world</div>
<div>See you in 1 day.</div>
<div>Hello cool world</div>
<div>See you in 3 days.</div>