Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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