Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Math operators

Arithmetic in templates with sum, sub, mul, div, mod, inc, dec, min, max, abs, ceil, floor, round, int, float, count, roman and rand, with examples for paging, percentages and grids.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/math-operators.md

On this page

Math operators

This page is a reference for calculations in templates. All come from eZTemplateArithmeticOperator (lib/eztemplate/classes/eztemplatearithmeticoperator.php).

Contents

  1. The operators
  2. Examples
  3. Notes

The operators

OperatorExampleResult
sumsum( 2, 3, 4 ) or 2|sum( 3 )9, 5
subsub( 10, 3 )7
mulmul( 4, 2.5 )10
divdiv( 10, 4 )2.5
modmod( 10, 4 )2
inc, dec$i|inc$i plus or minus 1
min, maxmax( $a, $b )the smaller / larger
abs, ceil, floor, round$x|round
int, float$text|inta number from a string
count$list|countnumber of items (an array's count, a string's length)
roman4|romanIV
randrand( 1, 6 )a random number (do not use inside cached output)

Examples

Number of pages:

{def $pages = ceil( div( $total, $limit ) )}

Offset of the current page:

{def $offset = first_set( $view_parameters.offset, 0 )|int}
{def $page = sum( div( $offset, $limit )|floor, 1 )}

A percentage class for a meter (admin4 has .a4-pct-0 to .a4-pct-100 in steps of 4):

{def $pct = mul( div( $done, $total ), 100 )|round}
<span class="a4-meter"><span class="a4-pct-{mul( div( $pct, 4 )|round, 4 )}"></span></span>

Columns for a grid:

{if mod( $index, 3 )|eq( 0 )}<div class="row">{/if}

(CSS grid usually makes such counting unnecessary.)

Notes

  • Division by zero: test the divisor first.
  • Template math is fine for presentation; business calculations (prices, taxes) belong in the shop's PHP.
  • Inside a view-cached template or a cache-block, rand returns the same value until the cache is rebuilt.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x