# Template Web Sample

CobolScript code can be embedded in a text file, and it can be used to make a web page.

## Setup

Install [Node.js](http://nodejs.org).

## Run

With the command line:

```
node server
```

The output:
```
Server started, listening at port 8000
```

Then launch http://localhost:8000 in your browser. It works!

![Factorial Web Sample](https://raw.github.com/ajlopez/CobolScript/master/images/templateweb.png)

The template file is `factorial.cobp` (actually, `.cobp` extension is reserved to this kind of web pages
with templates):
```
<h1>Factorial</h1>
<p>Page generated by CobolScript, using templates</p>
<table>
<tr><th align='right'>n</th><th align='right'>n!</th></tr>
<#
local n.
perform show-factorial using n varying n from 1 to 10.
#>
</table>
<#
.

show-factorial using n.
local result.
perform factorial using n giving result.
#>
<tr><td align='right'>${n}</td><td align='right'>${result}</td></tr>
<#
.

factorial using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
perform factorial using m giving m.
multiply n by m.
return m.
#>
```

CobolScript code is embedded between `<#` and `#>`. CobolScript expressions are embedded between `${` and `}`.

