luci-base: protect CBI forms with CSRF tokens
[project/luci.git] / documentation / Templates.md
1 LuCI has a simple regex based template processor which parses HTML-files to Lua functions and allows to store precompiled template files.
2 The simplest form of a template is just an ordinary HTML-file. It will be printed out to the user as is.
3
4 In LuCI every template is an object with an own scope. It can therefore be instanciated and each instance can has a different scope. As every template processor. LuCI supports several special markups. Those are enclosed in `<% %>`-Tags.
5
6 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.
7
8
9 # Builtin functions and markups
10 ## Including Lua code
11 *Markup:*
12         
13         <% code %>
14         
15
16
17 ## Writing variables and function values
18 *Syntax:*
19         
20         <% write (value) %>
21         
22
23 *Short-Markup:*
24         
25         <%=value%>
26         
27
28 ## Including templates
29 *Syntax:*
30         
31         <% include (templatename) %>
32         
33
34 *Short-Markup:*
35         
36         <%+templatename%>
37         
38
39
40 ## Translating
41 *Syntax:*
42         
43         <%= translate("Text to translate") %>
44         
45
46
47 *Short-Markup:*
48         
49         <%:Text to translate%>
50         
51
52
53 ## Commenting
54 *Markup:*
55         
56         <%# comment %>
57         
58
59 # Builtin constants
60 | Name | Value |
61 ---------|---------
62 |`REQUEST_URI`|The current URL (without server part)|
63 |`controller`|Path to the Luci main dispatcher|
64 |`resource`|Path to the resource directory|
65 |`media`|Path to the active theme directory|