Edit this page

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

This feature is experimental. Please share your experiences so we know what to keep or change.

Clones a template element.

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

Example

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

Passing variables

Any template variables can be passed as a second argument:

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

Parameters

template string|Element

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.

[data={}] Object optional

An object with template variables.

[options.origin] Element 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().