help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



[Overview][Constants][Procedures and functions] Reference for unit 'pwumain' (#powtils_main)

TemplateOut

Declaration

Source position: pwumain.pas line 146

function TemplateOut(

  const fname: String

):errcode;

Notes

Outputs a file which can contain $macro variables. This function is similar to the FileOut function except this function is template capable.

Example

The template file can include HTML and {$macrovar} or $macrovar style variables. To output your macrovar use the SetVar (SetWebVar) function:
begin
  SetVar('macrovar', 'value of var');
  TemplateOut('somefile.tpl');
end.
The TPL (template) file should look like:
 <html>
 <body>
   This is a $macrovar
 </body>
 </html>

Return codes

A warning will be shown in the web browser if a file is missing or there was as problem loading the template, if warnings are enabled in your config file (they are on by default). Also the function returns FILE_READ_ERR if not found, OK (1) if everything went okay.

In versions of Powtils previous to 1.6.0.1, this function did not return errors, it just threw errors to the screen if warnings were on in the config file.

Template Simplicity

The templating available with this function is extremely simple. If you are looking for more complex template system, we recommend looking or asking us for a third party template system (see for example Jorge's WebApplication framework).

Many template engines eventually become programming languages themselves (and in many cases, MVC is not actually a reality) and no HTML designer can learn and master each and every template system out there (Smarty, and 560 others). The TemplateOut() function will always remain fairly simple, while with third party extensions we welcome more advanced template engines. There are plans to add an #include directive into the TemplateOut() function though, and any other simple features that users feel the need for.

Tips

This is equivalent to the old WebTemplateOut function. The old WebTemplateOut is available for backwards compatibility.

The TemplateRaw function allows you to bypass security without any automatic filtering of malicious input that is done in TemplateOut.

The HTMLFilter parameter (in TemplateOut1 overloaded) tells the function whether or not to output filtered HTML for the macro variables. For example if you have set a macro var up that has less than and greater than symbols in it, these will be filtered first if htmlfilter is on.

Example: less than and greater than symbols are converted to html entities like & l t; and & g t;.

Other template engines

See also the WebApplication template/model/action/view extension by Jorge.





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505