Edit this page

up.fragment up.template.clone(template, [data], [options])
JavaScript function

Clones a template element.

Emits the up:template:clone event. You can use that event to integrate template engines like Mustache, EJS or Handlebars.

Templates

Example

let nodes = up.template.clone('#table-placeholder')
up.render({ fragment: nodes[0] })

Passing variables

Any template variables can be passed as a second argument:

let nodes = up.template.clone('#table-placeholder', { rows: 10 })

Parameters

template
required

The element to clone.

This is usually a <template> element or a <script> with a custom type.

You may also pass a selector for the element to clone.

stringElement
[data={}]
optional

An object with template variables.

[options.origin]
optional

An optional origin element used for template lookup.


Return value

A list of Node objects that represent the cloned templates.

You can pass this link to any rendering function, like up.render() or up.Preview#insert().