Using the ternary expression in the Sempare Template Engine for Delphi

Sempare Limited - Oct 28 - - Dev Community

The Sempare Template Engine (available at https://github.com/sempare/sempare-delphi-template-engine and GetIt) is a versatile templating system designed specifically for Delphi developers to streamline the creation and management of dynamic HTML, text, or any other text-based output formats. Whether you are building web applications, reports, or email templates, the Sempare Template Engine offers a powerful yet straightforward solution that integrates with minimal boilerplate into Delphi projects. The template engine has been around since 2019 and has many features for you to explore.

Sometimes, you may want an inline ternary expression to simplify more verbose if-expressions.

e.g. You may have something like:

<% x := 123 %>
<% if x > 100 %>
   a big value
<% else %>
   a low value
<% end %>
Enter fullscreen mode Exit fullscreen mode

We could convert the above into:

<% x := 123 %>
<% print('a big value' if x > 100 else 'a low value') %>
Enter fullscreen mode Exit fullscreen mode

Conclusion

The above tutorial illustrated how a ternary expression could

The Sempare Template Engine is very flexible, configurable and extensible, allowing for a good seperation of concerns between your business logic that will access data, and the templating engine that will render/present your data as required.

The template engine is available on https://github.com/sempare/sempare-delphi-template-engine and via Embarcadero GetIt.

Sponsorship Required

Please help us maintain the project by supporting Sempare via GitHub sponsors (https://github.com/sponsors/sempare) or via our payment link (https://buy.stripe.com/aEU7t61N88pffQIdQQ). Sponsors can obtain access to our integrated IDE wizard for RAD Studio.

. . . . . . . . . . .
Terabox Video Player