2023-08-10 18:10:01 +08:00
|
|
|
## Templates
|
|
|
|
|
|
|
|
See [online wiki](https://github.com/openwrt/luci/wiki/Templates) for latest version.
|
|
|
|
|
2015-06-16 16:11:03 +08:00
|
|
|
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.
|
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
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.
|
2015-06-16 16:11:03 +08:00
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
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.
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
## Builtin functions and markups
|
|
|
|
### Including Lua code
|
2015-06-16 16:11:03 +08:00
|
|
|
*Markup:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<% code %>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
### Writing variables and function values
|
2015-06-16 16:11:03 +08:00
|
|
|
*Syntax:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<% write (value) %>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
*Short-Markup:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<%=value%>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
### Including templates
|
2015-06-16 16:11:03 +08:00
|
|
|
*Syntax:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<% include (templatename) %>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
*Short-Markup:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<%+templatename%>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
### Translating
|
2015-06-16 16:11:03 +08:00
|
|
|
*Syntax:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<%= translate("Text to translate") %>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
*Short-Markup:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<%:Text to translate%>
|
|
|
|
```
|
2015-06-16 16:11:03 +08:00
|
|
|
|
|
|
|
|
2023-08-10 18:10:01 +08:00
|
|
|
### Commenting
|
2015-06-16 16:11:03 +08:00
|
|
|
*Markup:*
|
2023-08-10 18:10:01 +08:00
|
|
|
```
|
|
|
|
<%# 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
|