Misc

Generating Dynamic Content

Yaws has very nice support for generating dynamic content on the fly. We use embedded erlang code to generate the content. The Erlang code is separated from the HTML code by <erl> and </erl> markers. For example:

{header, Header} If a header structure is returned, an additional header is inserted among the HTTP headers generated by yaws. This is used to insert for example Set-Cookie headers. The Header variable must not be newline terminated.

{allheaders, Header} If an allheaders structure is returned, all previous headers that have been generated, including those default hedaers generated by yaws itself are erased, and replaced by the headers in Headers. The variable Headers must be a list of {header, Str} tuples. The Str must not be newline terminated.

{status, StatusCodeInt} Is used to force yaws to return a different status code than the default 200 code.

ok Do nothing.

{content, MimeType, Content} Sets the mime type, that is the Content-Type: header to be MimeType The default value is of course "text/html", but applications that generate i.e wml or pdf, must set the Content-Type. A pdf generating application can for example return the tuple {content, "application/pdf", PdfContentData}

{redirect, URL} a redirect is issued to the location in URL

{redirect_local, Path} a redirect is issued to the local server using the same method (http or https) as the incoming request and the path part of the location header to the value in Path .

{'EXIT', normal} which will terminate the client connection in an uncontrolled way.

{ssi, File, Delimiter, Bindings} Using this construct, we can deep inside a ehtml structure, return (ssi) Server Side Include content from a file. This construct is further described in ssi.yaws.

The embedded erlang code can also return a list of the above values. For example the following value

Each chunk of erlang code will be compiled into a separate module. The module names are automatically generated. If we have functions inside the erlang chunks that we want to call from other chunks or modules, it is possible to explicitly name the modue that will be used as in: