sgcHTML in WebStencils Templates

WebStencils is the server-side template engine of Delphi and C++ Builder 12.2 or newer, in the Web.Stencils unit. It runs on WebBroker and RAD Server and uses the @ syntax. sgcHTML components drop straight into those templates with no extra sgc code. Every component has a public HTML property, so you add the component to the processor with AddVar and write @\name.HTML where the markup belongs.

No extra sgc code
AddVar + @\name.HTML
WebBroker & RAD Server
htmx paging & sorting
Delphi & C++ Builder 12.2+

AddVar the Component, Write @\name.HTML

WebStencils reads the properties of the objects you hand to it. An sgcHTML component is one of those objects, and its HTML property returns the Bootstrap 5 markup of the component. That is all the template needs, so the interop works with the current sgcHTML release and needs no library change.

1. Set up the component

Create a StatCard, a Chart, a Grid or any other sgcHTML component and set its properties in Delphi or C++ Builder, exactly as you do when you serve the page from the sgcWebSockets server.

2. AddVar it

Register the component on a TWebStencilsProcessor or a TWebStencilsEngine with AddVar, under the name the template uses.

3. Write @\name.HTML

Put @\name.HTML in the template where the component belongs. WebStencils injects the markup of the component there, next to your own @ForEach, @if and layout code.

A StatCard in a WebStencils Template

A complete console program that renders a template with one StatCard. Both versions were compiled and run on Delphi and C++ Builder 12 and 13. WebStencils is a Delphi and C++ Builder framework, so there is no .NET version of this page.

program wst;

{$APPTYPE CONSOLE}

uses
  System.SysUtils, System.Classes, Web.Stencils,
  sgcHTML_Component_StatCard;

var
  oCard: TsgcHTMLComponent_StatCard;
  oProc: TWebStencilsProcessor;
  vOut: string;
begin
  oCard := TsgcHTMLComponent_StatCard.Create(nil);
  oProc := TWebStencilsProcessor.Create(nil);
  try
    oCard.Title := 'Revenue <Q4>';
    oCard.Value := '12,400';
    oProc.AddVar('card', oCard, False);
    vOut := oProc.ContentFromString(
      '<h1>@card.Title</h1>' + sLineBreak +
      '<div class="raw">@\card.HTML</div>');
    WriteLn(vOut);
  finally
    oProc.Free;
    oCard.Free;
  end;
end.
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <stdio.h>
#include <Web.Stencils.hpp>
#include "sgcHTML_Component_StatCard.hpp"
#pragma link "sgcHTML_Component_StatCard"

int _tmain(int argc, _TCHAR* argv[])
{
	TsgcHTMLComponent_StatCard *oCard = new TsgcHTMLComponent_StatCard((TComponent*)NULL);
	TWebStencilsProcessor *oProc = new TWebStencilsProcessor(NULL);
	try
	{
		oCard->Title = "Revenue <Q4>";
		oCard->Value = "12,400";
		oProc->AddVar("card", oCard, false);
		UnicodeString vOut = oProc->ContentFromString(UnicodeString("<h1>@card.Title</h1>") +
			sLineBreak + "<div class=\"raw\">@\\card.HTML</div>");
		printf("%s\n", AnsiString(vOut).c_str());
	}
	__finally
	{
		delete oProc;
		delete oCard;
	}
	return 0;
}

In C++ Builder, the (TComponent*)NULL cast is required, and the @\\ stays doubled inside a C++ string literal. When a template reads properties of your own C++ classes, declare those properties __published.

Both programs print the same two lines:

<h1>Revenue &lt;Q4&gt;</h1>
<div class="raw"><div class="card border-primary"><div class="card-body"><h6 class="card-subtitle mb-1 text-muted">Revenue &lt;Q4&gt;</h6><h2 class="card-title mb-0 text-primary">12,400</h2></div></div></div>

@\ Versus @, and Who Escapes What

WebStencils has two ways to write a value. The component markup must go in raw, while the text values inside it are already escaped by the component.

@\name.HTML injects the markup

The backslash form writes the value raw, so the <div> elements of the component reach the browser as markup and render as a card, a chart or a grid. Use it for the HTML property of every sgcHTML component.

@name.HTML encodes it as text

The plain form HTML encodes the value. Applied to the HTML property, the browser shows the tags as text instead of rendering them. The plain form is the right one for simple values such as @card.Title.

Components escape their own text

The HTML property goes in raw, but the text inside it is not raw. Each component escapes the text values it renders, so a title of Revenue <Q4> comes out as Revenue &lt;Q4&gt; inside the card, as the output above shows.

htmx Paging, Sorting and Forms in the Same WebBroker App

Static components only need the template. Interactive ones, such as grid paging and sorting or htmx forms, also need a server side that answers the htmx requests. Host TsgcHTMX_Engine_Server_WebBroker in the web module of the same WebBroker application. It answers the htmx requests and serves /bootstrap.min.css and /htmx.min.js, while WebStencils renders the pages with @LayoutPage, @RenderBody, @ForEach, @if and @query.

From the demo template templates\dashboard.html

@LayoutPage layout
<h1 class="h3 mb-3">Sales dashboard</h1>
<div class="row g-3 mb-4">
  <div class="col-sm-6 col-lg-3">@\revenueCard.HTML</div>
  ...
</div>
<div class="row g-3">
  <div class="col-lg-7">@\chart.HTML</div>
  ...

The layout page, the loops and the conditions stay in WebStencils. The StatCards, the chart and the grid come from sgcHTML, and the engine on the web module handles the requests the grid sends when the user changes the page or the sort order. See sgcHTML on WebBroker & DataSnap for the engine itself.

Versions and Editions

WebStencils needs Delphi or C++ Builder 12.2 or newer. It is not in 12.1 or older. The editions below follow the RAD Studio 13.2 feature matrix, and the current Community Edition is 13.0. On the sgcHTML side, the interop works with the current release.

RAD Studio editionWebStencilsWebBroker deployment on Linux
CommunityYes, from 13.0No
ProfessionalYesNo
EnterpriseYesYes
ArchitectYesYes
12.1 or older, any editionNoNo

New Demos in 2026.12

The demos Demos\Delphi\HTML\44.WebStencils and Demos\CBuilder\HTML\44.WebStencils ship with sgcWebSockets and sgcHTML 2026.12. They are one WebBroker application with three pages rendered by WebStencils templates. The interop itself works with the current release, only the demos are new in 2026.12.

Dashboard

StatCards, a bar chart and badges, each one written into the template with @\name.HTML inside a shared @LayoutPage.

Customers

A customer list built with @ForEach and @if, filtered by country through the ?country= query parameter.

Orders grid

An sgcHTML grid with htmx paging and sorting, answered by TsgcHTMX_Engine_Server_WebBroker in the same web module.

Learn More

WebBroker & DataSnap hosting

Serve sgcHTML pages from any WebBroker application or DataSnap server, with the engine that answers the htmx requests.

WebBroker & DataSnap hosting →

Online help

The WebStencils topic of the sgcHTML help, with the template syntax and the C++ Builder notes.

Online help →

Free trial

Download the sgcHTML trial for Delphi and C++ Builder, with every component and the demos.

Download the trial →
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Add sgcHTML Components to Your WebStencils Pages

Keep your WebStencils layouts and loops, and fill them with charts, grids, cards and forms built in Delphi or C++ Builder.