---
name: "up.template.clone"
area: "API"
kind: "JavaScript function"
parent: "up.fragment module"
url: "https://unpoly.com/api/up.template.clone"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.fragment module](https://unpoly.com/api/up.fragment.md)</nav>

# up.template.clone(template, [data], [options])

Clones a [template](https://unpoly.com/learn/templates.md) element.

Emits the [`up:template:clone`](https://unpoly.com/api/up:template:clone.md) event. You can use that event to integrate [template engines](https://unpoly.com/learn/templates.md) like Mustache, EJS or Handlebars.

<nav aria-label="Guides">

- [Learn: Templates](https://unpoly.com/learn/templates.md)

</nav>

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Passing variables](#passing-variables)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

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

## Passing variables {#passing-variables}

Any [template variables](https://unpoly.com/learn/templates.md#dynamic) can be passed as a second argument:

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

---

## Parameters {#parameters}

### template {#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.

Type: string | [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

### [data={}] {#data}

(optional)

An object with [template variables](https://unpoly.com/learn/templates.md#dynamic).

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects)

### [options.origin] {#options.origin}

(optional)

An optional [origin](https://unpoly.com/api/origin.md) element used for [template lookup](https://unpoly.com/learn/templates.md#lookup).

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

---

## Return value {#return-value}

A [list](https://unpoly.com/api/List.md) of [`Node`](https://developer.mozilla.org/en-US/docs/Web/API/Node) objects that represent the cloned templates.

You can pass this list to any rendering function, like [`up.render()`](https://unpoly.com/api/up.render.md) or [`up.Preview#insert()`](https://unpoly.com/api/up.Preview.prototype.insert.md).

Type: [List](https://unpoly.com/api/List.md)<[Node](https://developer.mozilla.org/en-US/docs/Web/API/Node)>

