WebStencils Components

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.

WebStencils Engine

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:

WebStencils Processor

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:

Adding Data with AddVar

The AddVar method is crucial for passing data from your Delphi code to your WebStencils templates. There are several ways to use AddVar:

  1. Direct object assignment:
  2. WebStencilsProcessor1.AddVar('user', UserObject);
  3. Using anonymous methods:
  4. WebStencilsProcessor1.AddVar('products',
      function: TObject
      begin
        Result := GetProductList;
      end);
  5. Using attributes: You can mark fields, properties, or methods in your classes with the [WebStencilsVar] attribute, then use AddModule to add all marked members as script variables:
  6. 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.