Tina4

Page Navigation#

TTina4HTMLPages provides SPA-style page navigation using TTina4HTMLRender. Pages are defined as a collection at design time. Navigation is triggered by `<a href="#pagename">` links.

Basic Setup#

pascal
// Drop TTina4HTMLPages and TTina4HTMLRender on the form// Link them at design time or runtime:Tina4HTMLPages1.Renderer := Tina4HTMLRender1;​// Pages are defined in the collection editor at design time,// or created at runtime:var Page := Tina4HTMLPages1.Pages.Add;Page.PageName := 'home';Page.IsDefault := True;Page.HTMLContent.Text := '<h1>Home</h1><a href="#about">Go to About</a>';​Page := Tina4HTMLPages1.Pages.Add;Page.PageName := 'about';Page.HTMLContent.Text := '<h1>About</h1><a href="#home">Back to Home</a>';

Pages can use Twig templates instead of raw HTML:

pascal
Tina4HTMLPages1.SetTwigVariable('userName', 'Andre');​var Page := Tina4HTMLPages1.Pages.Add;Page.PageName := 'dashboard';Page.TwigContent.Text :=  '<h1>Welcome {{ userName }}</h1>' +  '<a href="#settings">Settings</a>';

For file-based templates with {% include %} or {% extends %}:

pascal
Tina4HTMLPages1.TwigTemplatePath := 'C:\MyApp\templates';

Programmatic Navigation#

pascal
Tina4HTMLPages1.NavigateTo('dashboard');

Anchor href values are mapped to page names by stripping the leading # or /:

href valueMaps to PageName
#dashboarddashboard
/settingssettings
aboutabout

Events#

EventSignatureDescription
OnBeforeNavigateprocedure(Sender: TObject; const FromPage, ToPage: string; var Allow: Boolean)Fires before navigation; set Allow := False to cancel
OnAfterNavigateprocedure(Sender: TObject)Fires after the new page has been rendered

TTina4Page Properties#

PropertyTypeDescription
PageNamestringUnique name used as navigation target
TwigContentTStringListTwig template source (rendered via TTina4Twig)
HTMLContentTStringListRaw HTML (used when TwigContent is empty)
IsDefaultBooleanIf True, this page is shown on startup

TTina4HTMLPages Properties#

PropertyTypeDescription
PagesTTina4PageCollectionCollection of pages (design-time editable)
RendererTTina4HTMLRenderThe HTML renderer that displays the active page
ActivePagestringName of the currently displayed page
TwigTemplatePathstringBase path for Twig {% include %} / {% extends %}