Template

server.template() method is used to display static template file.

server.template(mix <path>, mix <header>) : bool --> function definition

Parameters

This method support maximum two parameters path and header

System Default path: 200, 403, 404, 500, 503

path

The Full Path of template File or default template code

header

Optional HTTP Header or Response Code

Return Values

Returns false if failed to display template file. Otherwise stdout data will be ignored and  template file will be shown and script execution will be end.

Examples

Example #1 Display system default page

This will display system default page:

server.template(200); ---> display system default page

Example #2 Display test file from Template

display single file from template file list:

server.template("/test.html"); ---> display test.html file from template file list

Example #3 Display file dynamically

If template file not exist on server we can show error page this way:

if not server.template(req.uri) then server.error("Template File Not Found", 404); end

Example #4 Display template file or dynamic page 

Try to serve static template File If not found then try to show page or error page

if not server.template(req.uri) then
  if not url.map("*", req.script_name or "index") then server.template(404) end
end

server.template method is very useful for handling requests correctly and display appropriate content.