Digest operators
Checksums and hashes of a string, for building ids, cache keys or class names. They are registered by
eZTemplateDigestOperator (lib/eztemplate/classes/eztemplatedigestoperator.php) through
lib/eztemplate/classes/eztemplateautoload.php. All work on the piped input and take no parameters.
Contents
The operators
md5
PHP md5(): 32 hex digits. Generated reference: md5.
crc32
eZSys::ezcrc32() (lib/ezutils/classes/ezsys.php): PHP crc32(), printed as an unsigned number when
[SiteSettings] 64bitCompatibilityMode=enabled in site.ini, so the value is the same on 32-bit and 64-bit PHP.
Generated reference: crc32.
rot13
PHP str_rot13(): every letter moved 13 places, other characters kept. It hides nothing; it only stops text from being
read at a glance. Generated reference: rot13.
sha1
PHP sha1(): 40 hex digits. See the next section before using it.
All four: input the string (piped), no parameters, return a string (crc32 a number).
'Fit & Healthy'|md5 = 'Fit & Healthy'|md5
'Fit & Healthy'|crc32 = 'Fit & Healthy'|crc32
'Fit & Healthy'|rot13 = 'Fit & Healthy'|rot13
'Fit & Healthy'|sha1 = 'Fit & Healthy'|sha1Output:
'Fit & Healthy'|md5 = 230d0ad476984ff3dba19ec739b09733
'Fit & Healthy'|crc32 = 2208743097
'Fit & Healthy'|rot13 = Svg & Urnygul
'Fit & Healthy'|sha1 = 2441fb64e95685d5f0064f97e86d06048e57a499A short, stable id for an element, from a node of a development installation (node 89) and its current version:
def $node = fetch( 'content', 'node', hash( 'node_id', 89 ) )
id-concat( $node.node_id, '-', $node.object.current_version )|md5|extract_left( 8 )Output:
id-0c7e77dbsha1 and the autoload list
The class adds sha1 to its operator list when PHP has the function, but the operator_names entry in
lib/eztemplate/classes/eztemplateautoload.php lists only crc32, md5 and rot13. The engine loads an operator
class at the first use of one of its listed names, and loading it registers every name the class offers. So sha1
works after md5, crc32 or rot13 has been used in the same request, as in the first example, and is "not
registered" before that, leaving the value unchanged:
['Fit & Healthy'|sha1]Output:
[Fit & Healthy]Logged by the template engine:
WARNING : Operator 'sha1' is not registeredUse md5 when you need a hash in a template, or register an operator of your own
(Registering operators).
What they are not for
These are not for passwords, signatures or anything an attacker must not forge: MD5 and SHA-1 are broken for those purposes, and a template is the wrong place for secrets anyway. Use them for ids and cache keys only.
The examples gave the same output interpreted and compiled on a development installation.
Related pages
- Text operators:
concatto build the string to hash - Cache blocks: keys for cache-block
- All template operators (generated)
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
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.