Template

Use templates to create dynamic content, including HTML and plain TEXT.

See Also: Generating Pages

cloud.template


Render

.render

cloud.template.render(template_file, template_values)

Parameters

Name Description Type Default Required
template_file The path to the template, relative to your tpl folder string nil Y
template_values A table of token=value attributes for the template. table nil N

Returns

Rendered template text.

Example

--using `index.tpl` from tpl/index.tpl

local page = {
  title = "Hello Lua",
  content = "Here is some content for the template"
}

local str = cloud.template.render( 'index.tpl', page )

--Return as HTML page
return str, cloud.HTML

Template (Abridged)

<!-- tpl/index.tpl -->
<html>
<head>
  <title>{{ page.title }}</title>
  ...
</head>
<body>
  <div>{{ page.content }}</div>
</body>
</html>