Library globals

Function globals . string . compileTemplate

View source

Get a function out of a string template for fast insertion of template
parameters. This allows to use the same templates as with most available tile
mapping engines (eg. Leaflet, Polymaps). Return a callable function object on
success, and nil if parsing the templated fails. See string._template_getargs
for more on calling a compile object.

Example (Build MapQuest tile url):

var makeUrl = string.compileTemplate(
"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg"
);
print( makeUrl({x: 5, y: 4, z: 3}) );

Output:

http://otile1.mqcdn.com/tiles/1.0.0/map/3/5/4.jpg

Parameters

template

type
optional