home
features
quick start
download
documentation
thymol files
configuration
message resources
control parameters
expression objects
thymol types
thymol API
thymol extensions
examples
sessions
say-hello
stsm example
with-dialect
extrathyme
petclinic
news
credits
user forum
issues
browser constraints
other known issues
create new issue
thymeleaf

thymoljs

thMappings

Another feature of Thymol is the thMappings structure that defines Thymol mappings.

Mappings are intended mainly to simplify the translation between URI values within a Thymeleaf template and real world URLs. Mapping URLs may locate resources in the local file system or on the network.

Mappings are defined in a JavaScript string array of key/value pairs called "thMappings".

The mapping translation is applied to template locator values and to URLs defined by Thymeleaf standard URL expressions (@{...}) after any variable substitutions and expression evaluations have been calculated.

The basic translation made is as follows: if the value of a URI matches a mapping key, then that URI is replaced by the mapping value.

There is also an "extended" mapping mode which when in force, causes the key match to be found true when the initial substring of a URI value is found to match the key value. (See thExtendedMapping section).

You can enable the extended mapping mode by setting the value of the thExtendedMapping parameter to "true".

Here is an example mappings definition set:

        var thMappings = [
            ["/webjars/bootstrap/2.3.0/css/bootstrap.min.css",        "http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap.min.css"],
            ["/jquery",                                               "http://code.jquery.com/mobile/1.3.1"],
            ["/thymeleaf",                                            "/home/fred/projects/new-site/templates"],
            ["/thymeleaf/welcome",                                    "/home/live/distr/WEB-INF/thymeleaf/welcome"],
            ["/resources",                                            "/home/fred/projects/new-site/resources"],
            ["/",                                                     "/home/live/distr/WEB-INF/thymeleaf/welcome.html"]
        ];

Under this example, a reference to "@{/thymleaf/hello.html}" would be translated into:

"/home/fred/projects/new-site/templates/hello.html"

and a reference to "@{/}" would translate to

"/home/live/distr/WEB-INF/thymeleaf/welcome.html".

Tip:

An effect similar to mapping can be accomplished using thVars, by defining a variable that simulates a URI or even a Thymeleaf function.

For example:

        var thVars = [
           ...
            ["#dates.format(visit.date.toDate(), \'yyyy-MM-dd\')",        "2013-07-12"],
           ...
        ];

This variable simulates the effect of a particular Thymeleaf #dates expression utility.