Spanish Total.js
English
Documentation For AI agents
Contents

ui-import

The attributes and configuration keys of the ui-import element.

.md GitHub
On this page

The <ui-import> element downloads HTML and inserts it into the page. The content can declare plugins and components, which are compiled after the insertion. Importing content explains the concept.

API

property

path="url"

Sets the URL of the content.

The url key has priority over this attribute. A URL with the prefix once or ! is imported only once in the page.

Importing a page
<ui-import path="/users.html"></ui-import>
Importing only once
<ui-import id="a" path="once /users.html"></ui-import>
<ui-import id="b" path="once /users.html"></ui-import>
property

config="key:value"

Configures the import.

The value is a list of key:value pairs. The keys are listed on this page.

URL in the configuration
<ui-import config="url:/users.html"></ui-import>
property

plugin="path"

Creates a scope directly on the element.

The value is the path of the scope.

A scope on the element
<ui-import plugin="users" path="/users.html"></ui-import>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log($('b').scope().path), 500);  // users
</script>
config

url:url

Sets the URL of the content.

The prefixes once and ! work as in the path attribute.

Setting the URL
<ui-import config="url:/users.html"></ui-import>
config

path:path

Replaces ~PATH~ and CLASS in the content.

The value also adds the path to <ui-plugin> elements without a path and to an anonymous PLUGIN(function(...)) declaration, so one file can be imported several times.

Adapting the content
<ui-import config="url:/part.html;path:users"></ui-import>
config

id:identifier

Replaces ~ID~ in the content.
Adapting the content
<ui-import config="url:/part.html;id:box1"></ui-import>
config

cache:expiration

Sets how long the response is cached.

The value is an expiration such as 5 minutes, or session. The default value is DEF.importcache, which is session.

Caching for five minutes
<ui-import config="url:/users.html;cache:5 minutes"></ui-import>
config

make:path

Transforms the content before the insertion.

The value is a path to a function or plugin/method. A ? in the value is replaced with the path key. The function receives the response, the element and the path key, and returns the content to insert. When it returns nothing, nothing is inserted.

Changing the response
<ui-import config="url:/users.html;make:common.prepare"></ui-import>

<script>
    window.common = { prepare: response => response + '<u>Added</u>' };
</script>
config

init:path

Calls a function after the insertion.

The value is a path to a function or plugin/method. A ? in the value is replaced with the path key. The function receives the element.

Running code after the insertion
<ui-import config="url:/users.html;init:common.ready"></ui-import>

<script>
    window.common = { ready: element => console.log(element.html()) };  // <b>Users</b>
</script>
config

target:selector

Appends the content to another element.

The value is a jQuery selector.

Inserting elsewhere
<ui-import config="url:/users.html;target:#box"></ui-import>
<div id="box"></div>
config

replace:true

Replaces the element with the content.
Replacing the element
<ui-import config="url:/users.html;replace:true"></ui-import>
config

reevaluate:true

Runs the scripts of the content on each import of the URL.

Without this key, the scripts run only the first time the URL is imported.

Running scripts repeatedly
<ui-import config="url:/script.html;reevaluate:true"></ui-import>
<ui-import config="url:/script.html;reevaluate:true"></ui-import>

<script>
    setTimeout(() => console.log(window.counter), 700);  // 2
</script>
Made in Europe