forked from erlyaws/yaws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindings.yaws
126 lines (90 loc) · 2.22 KB
/
bindings.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<erl>
out(A) ->
{ssi, "TAB.inc", "%%",[{"bindings", "choosen"}]}.
</erl>
<div id="entry">
<h2> Bindings </h2>
<p>
Bindings are the opposite of
<a href="ssi.yaws"> Server Side Includes (SSI)</a>.
SSI is used when entire pages are written largely in EHTML and
snippets of HTML, or more typically javascript code is
inserted into the EHTML
code.
</p>
<p> Bindings are used the other way around. Essentially entire
pages are written in regular HTML but parts of the HTML needs to be
dynamically generated.
</p>
<p>The yaws callback out/1 can return
</p>
<div class="box">
<pre>
{bindings, [{Key1, Value2}, {Key2, Value2} .....]}.
</pre>
</div>
<p>All bindings can then be used in the rest of yaws code (in HTML source and
within erl tags). In HTML source %%Key%% is expanded to Value and
within erl tags yaws_api:get_binding(Key) can be used to extract Value.</p>
<p>With the binding feature it is easier to write transparent yaws code making
it easier to to work together with Web people knowing little or
nothing about Erlang.</p>
<p>
An example:
</p>
<div class="box">
<verbatim>
<erl>
out(A) -> {bindings, [{"A", "foo"}, {"B", "baz"}]}.
</erl>
<html>
<body>
<p>%%A%%</p>
<p><font size="4">%%A%% != %%B%%</font></p>
<p>An enormous amount of plain html source here.</p>
<erl>
out(A) ->
Value = yaws_api:binding("A"),
{ehtml, {ul, [],
[{li, [],
Value},
{li, [],
"gazonk"}]}}.
</erl>
%%A%% = %%A%% (hit me)
</body>
</html>
</verbatim>
</div>
<p>
Which expands to:</p>
<div class="box">
<verbatim>
<html>
<body>
<p>foo</p>
<p><font size="4">foo != baz</font></p>
<p>An enormous amount of plain html source here.</p>
<ul>
<li>foo</li>
<li>gazonk</li></ul>
foo = foo (hit me)
</body>
</html>
</verbatim>
</div>
<p> And is rendered as:</p>
<div class="box">
<p>foo</p>
<p><font size="4">foo != baz</font></p>
<p>An enormous amount of plain html source here.</p>
<ul>
<li>foo</li>
<li>gazonk</li>
</ul>
foo = foo (hit me)
</div>
</div>
<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>