Logic and calculation
Content below is copied from the official Neto B@SE docs so you can edit and annotate it locally. Original: Logic and calculation.
forloop
For-next loop with an index between the start and end values.
Example
Parameters
| Name | Options | Description |
|---|---|---|
| start | Integer | Starting value |
| end | Integer | Final value |
| *header | HTML & b@se tags | Renders a single usable space above the body |
| *body | HTML & b@se tags | Runs for each iteration in the tag |
| *footer | HTML & b@se tags | Renders a single usable space below the body |
| *ifempty, *ifempty | HTML & b@se tags | If the forloop returns no results, this block is used instead |
Note: this function works by incrementing the value by 1.
Data Tags (body)
| Name | Example | Description |
|---|---|---|
[@index@] | 0 | Counter starting at 0 |
[@counter@] | 1 | Counter starting at 1 |
[@from@] | 1 | Starting value. Same as start param |
[@to@] | 10 | Ending value. Same as end param |
calc
Lets you perform calculations with b@se tags.
Example
Add to the existing value in a variable: use += to add to an existing value.
Assign a value to a variable: use = so the variable now has the value.
Remainder: when using division, use % to display only the remainder.
Power (exponents): e.g. eight to the fifth power using **.
Usage
The calc tag lets you perform arithmetic on b@se tags and static integers. You can perform calculations between static values, b@se tags, and results from formatting with any of the operators below. This can also be combined with the round tag for more advanced calculations.
Order of calculation: The calc function follows standard rules: multiplication and division first, then addition and subtraction. Use brackets ( ) to force a calculation to be done before another.
Parameters
| Name | Description |
|---|---|
* | Multiply |
/ | Divide |
+ | Add |
+= | Add to the existing value in a variable |
- | Subtract |
= | Assign a value to a variable |
% | Remainder |
** | Power (exponents) |
( ) | Brackets to specify the order of operations |
if
Neto by Maropost’s IF, IF THEN & ELSE function.
Example
Usage
Simple statements: e.g. display “Free shipping” only when the price is greater than $200. Since the product either has a price > $200 or not, the if logic is the right choice.
Complex statements: A logic statement can contain two or more parameters. If you only want “free shipping” when price > $200 and the description is not empty, combine conditions.
Misc fields and Custom Configs: Use Custom Product Fields or globally accessible variables (Custom Configs under Settings & Tools) to show content or behaviour based on those fields. Custom Product Fields and Custom Configs can use Boolean output (True/False).
Correct: Both true and false (as control panel values) are true in traditional boolean logic—they are non-empty values. So if the control panel value is set to true or false, content can still display because neither is a “false” value in that sense.
Incorrect: If you expect the string “false” to behave like a logical false, it won’t—it’s still a truthy value.
Custom Configs output proper Boolean values and are not subject to that ambiguity.
Operators
| Operator | Meaning |
|---|---|
== | Equal to (integers) |
eq | Equal to (strings) |
!= | Not equal (integers) |
ne | Not equal to (strings) |
< | Less than |
> | More than |
<= | Less than or equal to |
>= | More than or equal to |
or | Either this or that |
and | Must be this and that |
like | Exists within string |
not like | Inverse of like |
set
Lets you set and read your own variables using b@se tags.
Example
Setting the tag: use the set function to assign a value (e.g. from another tag or a calculation).
Using the tag: reference the variable elsewhere with [@your_var_name@].
Usage
The set function lets you create your own tags in B@se. Once set, you can use them like any other tag—in parameters, inside other tags, in logic, etc. For example, use format to turn an existing tag into a unix time code, then store it with set and use that new tag on the page.
Scoping
By default, a variable’s scope is limited to the function param it was defined in.
Caret for scope: The caret ^ can hoist a variable’s scope up one or more levels. Use multiple carets to hoist many levels (e.g. ^^^varname at three functions deep to make it page-level). If a variable is not defined in the current scope, it is inherited from the parent. To read an inherited variable you can leave off the carets; to set it you must use carets to specify the scope.
The ‘session’ function
Using the special session value, you can store data in a variable that is then available site-wide. Session tags do not work when Varnish caching is enabled. Use the session shorthand so the variable is available on other pages/templates.
round
Rounds a figure based on the parameters.
Example
Usage
The round tag rounds a number to the nearest decimal place you specify. You can also round to the nearest whole number.
Parameters
| Name | Options | Description |
|---|---|---|
| value | Number | The value you will round |
| decimal_place | Integer | The decimal place to round to; cannot be used with whole |
| whole | — | Rounds to the nearest whole number; cannot be used with decimal_place |
data
Legacy. Largely superseded by if and calc.
Neto by Maropost’s legacy tag for conditionals and calculations.
Example
Usage
Dynamically referencing tags: Data encapsulated in the function can be referenced dynamically.
Calc: The data tag can be used as a calc function.
If statement: It can also be used as an if statement (e.g. display content only when a value is greater than zero).
Parameters
| Name | Options | Description |
|---|---|---|
id:'' | String | Sets the ID for the data so it can be referenced elsewhere. Can also be the variable name in calculations |
if:'' | eq, ne, =, ==, !=, <, >, etc. | The initial condition |
calc:'' | *, /, +, %, **, ( ) | Calc for arithmetic within the conditional |
value:'' | Number or variable | Value to compare against |
cvalue:'' | Number | Succeeds the value of the variable in calc order |
fvalue:'' | Number | Precedes the value of the variable in calc order |
*if_true | HTML & b@se tags | Output when the condition is true |
*if_false | HTML & b@se tags | Output when the condition is false |
*case_# | HTML & b@se tags | Case designation; replace # with 1–999 |
*case_#_value | HTML & b@se tags | Value for that case; replace # with 1–999 |
Your annotations
Use this section to note anything that’s incorrect in the official docs or extended by your implementation.