EN IT
Open2b version 7.8

Scriggo

Scriggo is a modern and powerful template system, developed by Open2b and based on Google’s Go language. Scriggo lets you structure template HTML files to make development faster and easier, and it adds variables, macros, and functions to insert dynamic store content that varies from page to page.

When needed, Scriggo also provides a powerful and complete programming language integrated directly into the template, safe to use both when the store is on your own server and when it is in the cloud.

Syntax

The following is a minimal example of a template page written with Scriggo:

{% extends "layout.html" %}
{% import "imports/banners.html" %}
{% macro Body %}
  {{ Banner() }}
  <ul>
    {% for product in products %}
    <li><a href="{{ product.URL }}">{{ product.Name }}</a></li>
    {% end for %}
  </ul>
  {{ render "pagination.html" }}
{% end macro %}

Double curly braces:

{{ product.Name }}
allow you to display the content of a variable and, more generally, the result of evaluating an expression.

Single curly braces with the percent sign:

{% if product.Stock > 10 %} good availability {% end %}
are instructions that let you structure the template, execute repeated parts or conditional parts, and declare and assign variables.

Instructions

There are several instructions that let you structure template pages into different code blocks that can be reused, such as show, macro, extends and import.

The if instruction lets you execute code based on a condition, and the for instruction lets you repeat code, such as iterating over a product list. These are joined by the switch instruction and other forms of for.

The var instruction lets you declare new variables, and assignment instructions like = let you change their values.

Learn more

Operators

Operators let you define more complex expressions from variables and basic values. Scriggo provides all Go operators including arithmetic, comparison, and logical operators. In addition, it has three logical operators and, or and not that work on any data type.

Learn more

Data types

Each variable has a type that indicates the values it can contain, the operations that can be performed on it, and which methods can be called on it.

There are basic types, such as string, int and bool, structures with multiple fields and their own names, and lists of values called “slices.”

Some variables can be displayed directly in an HTML page:

{{ name }}

These are variables with a basic type and variables that support the HTML method as described in the type documentation.

Learn more

Variables

Variables contain store data that can be shown on the site as-is, used in expressions, or passed as arguments to macros, functions, and methods.

Each site page has global variables that change based on the template page. The content of these variables depends on the page shown to the customer. For example, on the product.html template page the predeclared variable name is available and contains the product name, which changes depending on the product being rendered.

Learn more