luci/docs/Templates.md
Sergey Ponomarev 155d2bdd6e docs: Synchronize with Wiki
The Wiki on GitHub has newer version of documentation.
Still we may have references to the docs folder.
Update all pages but also add a notice:

See [online wiki](https://github.com/openwrt/luci/wiki/) for latest version.

The LAR page is removed because there no any mentions of it anywhere in Luci.

This closes #2360

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
2023-08-10 13:10:37 +03:00

68 lines
1.5 KiB
Markdown

## Templates
See [online wiki](https://github.com/openwrt/luci/wiki/Templates) for latest version.
LuCI has a simple regex based template processor which parses HTML-files to Lua functions and allows to store precompiled template files.
The simplest form of a template is just an ordinary HTML-file. It will be printed out to the user as is.
In LuCI every template is an object with an own scope
It can therefore be instanced and each instance can have a different scope.
As every template processor. LuCI supports several special markups. Those are enclosed in `<% %>`-Tags.
By adding `-` (dash) right after the opening `<%` every whitespace before the markup will be stripped.
Adding a `-` right before the closing `%>` will equivalently strip every whitespace behind the markup.
## Builtin functions and markups
### Including Lua code
*Markup:*
```
<% code %>
```
### Writing variables and function values
*Syntax:*
```
<% write (value) %>
```
*Short-Markup:*
```
<%=value%>
```
### Including templates
*Syntax:*
```
<% include (templatename) %>
```
*Short-Markup:*
```
<%+templatename%>
```
### Translating
*Syntax:*
```
<%= translate("Text to translate") %>
```
*Short-Markup:*
```
<%:Text to translate%>
```
### Commenting
*Markup:*
```
<%# comment %>
```
## Builtin constants
* `REQUEST_URI`: The current URL (without server part)
* `controller`: Path to the Luci main dispatcher
* `resource`: Path to the resource directory
* `media`: Path to the active theme directory