Zen: utilities

Back to Zen homepage

prev

1. custom extension

There are three phases of transpilling the template code into HTML code:
  1. Preprocessing where $zen_pre[] global array of preprocessors takes the code as their argument and returns the transpilled code. The output is PHP, so all curly bracket replacement for angle brackets with question marks happens here (Zen -> PHP).
  2. PHP phase where PHP executes the preprocessed code (PHP -> HTML).
  3. PostProcessing where $zen_post[] global array some afterworks can be done (HTML -> HTML).
Feel free to add your own extension int one of these two arrays, like the dummy one below. This function needs to be defined and added before the zen function is called, not in the template itself when the preprocessing already started. So the php function below was not defined here (only displayed), but in the test.php script that loads the zen and processes this file.
<? include "zen.php"; include "zen_ext.php"; $zen_pre[] = fn($_)=>strtr($_, ["hahaha"=>"hohoho"]); echo zen("myfile.zen"); ?> {="Santa says hahaha"}

Result

Santa says hohoho

2. error reporting

Zen defines following functions that can be redefined: These functions gets a single argument describing the error. The default behavior is keep silent, but can be redefined before the zen script executes. They are not perfect yet and require further improvement in various error scenarios.