Skip to content
Newer
Older
100644 117 lines (77 sloc) 2.11 KB
379666b @klacke documented jockes new bindings feature
authored
1 <erl>
2 out(A) ->
3 [{ssi, "HEAD", [],[]},
4 {ssi, "EXHEAD", [],[]}].
5 </erl>
6
7
9c5b959 @klacke ""
authored
8 <h2> Bindings </h2>
379666b @klacke documented jockes new bindings feature
authored
9 <p>
d02b965 @klacke qnx port + docs overhaul by cschatz@networkadvantage.biz
authored
10 Bindings are the opposite of <a href="ssi.yaws"> Server Side Includes (SSI)</a>.
11 SSI is used when entire pages are written largely in EHTML and
12 snippets of HTML, or more typically javascript code is inserted into the EHTML
379666b @klacke documented jockes new bindings feature
authored
13 code.
14
d02b965 @klacke qnx port + docs overhaul by cschatz@networkadvantage.biz
authored
15 <p> Bindings are used the other way around. Essentially entire
379666b @klacke documented jockes new bindings feature
authored
16 pages are written in regular HTML but parts of the HTML needs to be
17 dynamically generated.
18
19 <p>The yaws callback out/1 can return
20
21 <div class="box">
22 <pre>
23 {bindings, [{Key1, Value2}, {Key2, Value2} .....]}.
24 </pre>
25 </div>
26
27
28 <p>All bindings can then be used in the rest of yaws code (in HTML source and
29 within erl tags). In HTML source %%Key%% is expanded to Value and
30 within erl tags yaws_api:get_binding(Key) can be used to extract Value.
31
d02b965 @klacke qnx port + docs overhaul by cschatz@networkadvantage.biz
authored
32 <p>With the binding feature it is easier to write transparent yaws code making
379666b @klacke documented jockes new bindings feature
authored
33 it easier to to work together with Web people knowing little or
34 nothing about Erlang.
35
36 An example:
37
38
39 <div class="box">
40 <pre>
41
42 &lt;erl&gt;
43 out(A) -&gt; {bindings, [{"A", "foo"}, {"B", "baz"}]}.
44 &lt;/erl&gt;
45
46 &lt;html&gt;
47 &lt;body&gt;
48 &lt;p&gt;%%A%%&lt;/p&gt;
49 &lt;p&gt;&lt;font size="4"&gt;%%A%% != %%B%%&lt;/font&gt;&lt;/p&gt;
50 &lt;p&gt;An enormous amount of plain html source here.&lt;/p&gt;
51
52 &lt;erl&gt;
53 out(A) -&gt;
54 Value = yaws_api:binding("A"),
55 {ehtml, {ul, [],
56 [{li, [],
57 Value},
58 {li, [],
59 "gazonk"}]}}.
60 &lt;/erl&gt;
61
62 %%A%% = %%A%% (hit me)
63 &lt;/body&gt;
64 &lt;/html&gt;
65 </pre>
66 </div>
67
68
69 <p>
70 Which expands to:
71
72 <div class="box">
73 <pre>
74
75
76
77 &lt;html&gt;
78 &lt;body&gt;
79 &lt;p&gt;foo&lt;/p&gt;
80 &lt;p&gt;&lt;font size="4"&gt;foo != baz&lt;/font&gt;&lt;/p&gt;
81 &lt;p&gt;An enormous amount of plain html source here.&lt;/p&gt;
82
83 &lt;ul&gt;
84 &lt;li&gt;foo&lt;/li&gt;
85 &lt;li&gt;gazonk&lt;/li&gt;&lt;/ul&gt;
86
87 foo = foo (hit me)
88
89
90
91 </pre>
92 </div>
93
94
95 And is rendered as:
96 <div class="box">
97 <p>foo</p>
98 <p><font size="4">foo != baz</font></p>
99 <p>An enormous amount of plain html source here.</p>
100
101 <ul>
102 <li>foo</li>
103 <li>gazonk</li></ul>
104
105 foo = foo (hit me)
106 </div>
107
108
109
110
111
112 </html>
113
114
115
116
Something went wrong with that request. Please try again.