The absolutely most simple example is a HTML file which doesn't contain any embedded erlang code at all.
The file simple_ex1.yaws contains the following HTML code.
<html> <h1>Hello world </h1> </html>
Since the file has the suffix .yaws, the file will be processed by the Yaws dynamic compiler, but since no embeddded erlang code is found, the data from the file will be delivered untouched.
The file simple_ex2.yaws contains the following HTML code.
<html> <h1> Yesssssss </h1> <erl> out(Arg) -> {html, "<h2> Hello again </h2>"}. </erl> </html>
The file has one very simple function which just returns a tuple {ok, String}
The String will be substituted into the delivered HTML data instead of the Erlang code.
The file simple_ex2.yaws returns html embedded as a string. A tighter coupling to Erlang is provided by a construct known as "ehtml". As in simple_ex3.yaws as ehtml
<html> <h1> Yesssssss </h1> <erl> out(Arg) -> {ehtml, [{h2, [{class, "foo"}], "Hello yet again"}]}. </erl> </html>
When writing yaws code, all classic erlang libraries are available, however, the module yaws_api which is included in the load path for yaws modules contains an number of usefule functions, here is a small example in simple_ex4.yaws
<html> <h1> simple ex 3</h1> <erl> out(Arg) -> {html, f("Printing the arg structure :" "~n<pre>~p~n</pre>~n", [Arg])}. </erl> </html>
The above code illustrates two points:
The function f/1 which is available in the yaws_api module. It's just a shortcut convenience to io_lib:format/2. The yaws_api module contains many convenience functiond for yaws coders.
The second point is a printout of the #arg record which is passed to the out/1 function. If you take the time to work with yaws, the Arg passed to the out/1 functions will become very familiar. It is the main mechanism which is used to pass data from the webserver to the application.