Hello world

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.

Hello world again

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.

And yet again

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>


Print the #arg record

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:

Valid XHTML 1.0!