WebStencils introduces two main components that work together to process your templates and generate the final HTML output: the WebStencils Engine and the WebStencils Processor.
The WebStencils Engine is the central component that manages the overall processing of your templates. It can be used in two primary scenarios:
Key properties and methods of TWebStencilsEngine include:
Dispatcher: Specifies a file dispatcher (implements IWebDispatch) for
post-processing of text files.PathTemplates: A collection of request path templates used for matching and processing
requests.RootDirectory: Specifies the file system root path for relative file paths.DefaultFileExt: Sets the default file extension (default is '.html').AddVar: Adds objects to the list of script variables available to processors.AddModule: Scans an object for members marked with [WebStencilsVar] attributes and
adds them as script variables.The WebStencils Processor is responsible for processing individual files (typically HTML) and their associated templates. It can be used standalone or created and managed by the WebStencils Engine.
Key properties and methods of TWebStencilsProcessor include:
InputFilename: Specifies the file to process.InputLines: Allows direct assignment of content to process.Engine: Specifies the engine to inherit data variables, event handlers, etc. (optional).Content: Produces the final processed content.AddVar: Adds objects to the list of script variables available to the processor.The AddVar method is crucial for passing data from your Delphi code to your WebStencils templates.
There are several ways to use AddVar:
WebStencilsProcessor1.AddVar('user', UserObject);
WebStencilsProcessor1.AddVar('products',
function: TObject
begin
Result := GetProductList;
end);
[WebStencilsVar] attribute, then use AddModule to add all marked members as script
variables:
type
TMyDataModule = class(TDataModule)
[WebStencilsVar('customers', false)]
FDMemTable1: TFDMemTable;
[WebStencilsVar('users')]
FUsers: TUsers;
end;
WebStencilsProcessor1.AddModule(DataModule1);
It’s important to keep in mind that only objects with the GetEnumerator method, where the enumerator
returns an object value, can be used. Records can’t be used from WebStencils.