WEBSALE template engine
The WEBSALE template engine is used for the complete creation and design of the storefront. You do not need knowledge of programming languages such as PHP or Java, nor knowledge of database access, to create and customize your individual WEBSALE online shop. With the WEBSALE template engine, dynamic content in the online shop can be easily displayed — entirely without complex backend logic. As a template manager, you can fully focus on HTML, CSS, and JavaScript and embed dynamic data such as product information, user profiles, or prices with the help of our template engine and template language.Basics and syntax of the WEBSALE template engine
In the WEBSALE template environment, all templates are based on standard HTML files with the extensions.htm or .html, which are stored within the shop’s directory structure. Within these HTML files, so-called template tags can be used to embed dynamic content or language-dependent texts in the frontend.
Template tags allow the inclusion of:
- Text snippets for language-dependent content.
- Placeholders for dynamic content such as product data, user data, or shop functions.
Text snippets
Text snippets are used to centrally manage language-dependent texts such as button labels or headings and to insert them into templates. Their syntax is simple and unambiguous:Placeholders (for dynamic content)
Placeholders are used to embed dynamic data that is provided by the backend at runtime. The syntax is HTML-like and uses double curly braces{}:
Standard escaping
The WEBSALE template engine has built-in standard escaping that is automatically applied to all dynamically embedded content. This ensures that HTML or JavaScript code contained, for example, in product data or CMS content is not interpreted but displayed as plain text. Many contents in the shop — e.g., product descriptions, CMS articles, or other editorial texts — contain HTML for formatting. To prevent these contents from being unintentionally executed as actual HTML code, automatic escaping is applied during output with{{= ... }}.
Example: Standard escaping enabled
! is used instead of =:
Variables
With the WEBSALE template language, you can output the data provided by the shop system. Each page rendered by the template engine receives the data needed to display the requested content. This data is stored in so-called template variables. All template variables can be called via the template language with a$ followed by the variable name. Variable names can be chosen freely.
There are also system variables that begin with $ws and whose names are predefined, e.g., $wsProduct, $wsCategory, etc. A complete overview of the WEBSALE system variables and more information about variables in general can be found here.
Setting & using variables
Example: New variable$wsProduct.load('1234') loads the product data of the product with the item number 1234. This is stored in the variable $myProduct and can be used later.
Example: Using the variable
- The product data is stored in
$myProduct. - The product name, description, and price are dynamically inserted into the template.
. between the individual levels.
In this example:
$productis the main variable for the product.customreferences custom data of the product.mainImageindicates the main image of the product.thumbnailaccesses the smaller version of the image.
Scope of variables
The scope of a variable defines where it can be used in the template. Variables that are defined outside of scope statements such asif or foreach are valid throughout the entire template:
Modifiers
Sometimes it is not enough to simply output the content of a variable — the value must first be changed or adjusted. This is exactly what modifiers are for. Modifiers can be applied to any variable to change its content. To do so, simply append a| (pipe character) and the modifier name to the corresponding variable. Additional parameters are added with :.
Example: Truncating the product description
truncate modifier is applied to the product description. It truncates the text to a maximum length of 120 characters.
Examples: Applying multiple modifiers to a variable
You can also apply multiple modifiers to a variable in succession. They are processed in the order in which they are specified.
A complete list of all modifiers and their descriptions can be found in the modifiers overview.
Conditions
The WEBSALE{if} conditions allow the same flexibility as in PHP or JavaScript, except for a few extensions for the template engine. Every {if} must be combined with a {/if}. {else} and {elseif} are also allowed. All common PHP comparison operators and functions, such as ||, or, &&, and, is_array(), etc., are allowed.
With WEBSALE {if} conditions, you can vary the output in the storefront depending on certain conditions. To decide what is output, you can define a condition that checks a variable. A simple condition is represented by an {if} block that contains a check. This block is executed only if the check is true.
Example:
$myProduct.description has content. If so, its content is output. If not, the alternative content in the else block is rendered. Here we use the short description.
In addition to if and else, more complex conditions can also be defined by adding {elseif}. This makes it possible to combine multiple checks in a single condition.
Example: Greeting the visitor in the online shop
- A personal greeting is displayed when an existing customer logs in.
- A different greeting is displayed when a new customer logs in.
- A general message is displayed for all visitors who are not logged in.
>or<for comparing the quantity of a product
Loops
Loops make it possible to iterate through an array containing multiple data records (e.g., products) and automatically generate content for each individual record. This allows you to efficiently create repeating structures such as product lists, image galleries, or similar content. Aforeach loop is opened with the {{ foreach }} tag and closed with {{ /foreach }}. The name of the loop (the so-called loop variable) can be defined freely and may contain letters, numbers, and underscores.
The foreach loop runs through each element of the array once and executes the enclosed code section for each element. With each iteration, the current element is assigned to the loop variable.
Example: Product list of a category
5678 and creates a new <div> element for each product.
If no products are found in the category, the foreachelse section is executed and a corresponding message is displayed.
Complete information on loops can be found here.
