Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

texl

The texl namespace is bound by the Texl engine in every template. It is not available in plain Swan.

texl.import

texl.import uri -> Promise

Loads the document at uri, renders it, and returns a promise of a namespace that describes it:

MemberTypeContent
uriTextThe full URI of the document
sourceTextThe template source
dataNamespaceThe names the document's tags bound
textTextThe rendered text
tagsListOne namespace per tag, in the order of the source

Each item of tags describes one tag, also a tag that writes nothing:

MemberContent
startwhere the tag starts in source, in bytes
endwhere it ends in source, just after %>
out_startwhere its output starts in text, in bytes
out_endwhere its output ends in text
valuethe value that the tag wrote

If the document cannot be loaded, the promise resolves to an Undefined value with the operation "document.load", which says why (see Missing documents). If the import would close a cycle (a document importing itself, directly or through other documents), texl.import returns Undefined instead of a promise.

A relative uri is resolved against the URI of the importing document, and the fragment (#...) is ignored. The document renders in its own scope: it does not see the names of the importer. Within one rendering, each document is loaded and rendered at most once: importing it again, even through a different relative path, returns the same promise. A load that failed is tried again.

If the server answers with a redirect to another address, the document is the one at that final address: it is its uri, and its own relative imports start from there. Imports through different addresses that lead to the same document share it, and a document that imports itself through another address is a cycle like any other.

texl.import exists only in documents. In a context created by a host program to keep names across renders, texl has no import.

<% texl.import("partials/header.texl") ~> (doc -> doc.text) %>

See Documents and imports for the details.