ui-import
The attributes and configuration keys of the ui-import element.
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.
path="url"The url key has priority over this attribute. A URL with the prefix once or ! is imported only once in the page.
<ui-import path="/users.html"></ui-import>
<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.
config="key:value"The value is a list of key:value pairs. The keys are listed on this page.
<ui-import config="url:/users.html"></ui-import>
property
plugin="path"
Creates a scope directly on the element.
plugin="path"The value is the path of the scope.
<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.
url:urlThe prefixes once and ! work as in the path attribute.
<ui-import config="url:/users.html"></ui-import>
config
path:path
Replaces ~PATH~ and CLASS in the content.
path:pathThe 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.
<ui-import config="url:/part.html;path:users"></ui-import>
config
id:identifier
Replaces ~ID~ in the content.
id:identifier<ui-import config="url:/part.html;id:box1"></ui-import>
config
cache:expiration
Sets how long the response is cached.
cache:expirationThe value is an expiration such as 5 minutes, or session. The default value is DEF.importcache, which is session.
<ui-import config="url:/users.html;cache:5 minutes"></ui-import>
config
make:path
Transforms the content before the insertion.
make:pathThe 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.
<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.
init:pathThe 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.
<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.
target:selectorThe value is a jQuery selector.
<ui-import config="url:/users.html;target:#box"></ui-import>
<div id="box"></div>
config
replace:true
Replaces the element with the content.
replace:true<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.
reevaluate:trueWithout this key, the scripts run only the first time the URL is imported.
<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>