Repository navigation
Rendering
Ctrl+F9 (Run > Run) in a template renders it through PHP and the real Div engine, and shows the result next to the code. (In a PHP script the same key runs the script: see Running PHP.)


While Div works, a box like Turbo Pascal's Compiling box shows the template, the data file, the engine and a clock; big templates can take a while, and Esc stops the render.
Under them runs a bar in Norton Commander's style, drawn with the blocks of the PC's own character set: █ and ▓ fill a track of ░. Div does not tell how far it is, so a block goes back and forth over the track while it works; when it ends the bar fills, whatever the verdict; only a stop (Esc) leaves the track as it was. The same box, and the same bar, come with running PHP (see Running PHP), checking (Alt+F9) and the Render Trace.
When it ends, the box gives the verdict, Success, Warnings or Errors, with Div's version, the size of the output and the number of messages. The output is already behind it; any key closes the box. It also closes by itself: after two seconds on a success, after five when there are warnings or errors, so you have time to read them (they are in the Messages window too).

- The template: the active one; or, from a data file, the template it belongs to; or the last rendered one. Its unsaved edits are included, and its real path is given to Div so that relative includes work. Untitled templates are not rendered: see Save first in Checking Templates.
-
The data: by Div's convention
page.tpltakespage.json, next to it. Run > Data file… chooses another file, and divide remembers the choice in the project's.div/data-files.json(two paths relative to the project), so it holds when you open the project again; the dialog's Default button forgets it and goes back to the convention. A template or data file outside the project is chosen for the session only. Its data can also come from a script of the project: see Data from a provider below. Run > Edit data opens the data file (creating it if needed). The editor buffer is used if the data file is open. - The working directory is the project folder, as for include checks.
The first render places the template on the left and the Output on the right. The Output window is read-only and highlighted, so Div tags that were left unprocessed stand out. Its status line says what was rendered: index.tpl + index.json · Div 6.1.2 · 0.08s.
Some templates do not render with a data file as it is: the generator builds their data in code first (it adds keys, fills defaults). A provider is a PHP script of your project that prints that data as JSON, so the template renders with what the generator really gives it. Set it in the project's .div/data-files.json, in place of the data file:
{"templates": {"templates/dto.tpl": {"provider": {"php": "tools/template-data.php", "args": ["model/package_info.json"], "timeout_seconds": 10}}}}-
phpis a script of the project (a path relative to it; one that leads outside the project is not run).argsandtimeout_seconds(1 to 60, 10 by default) are optional. - divide runs
php SCRIPT ARGSwith the PHP it uses, in the project folder, with nothing on its input andDIVIDE_TEMPLATE(the template, relative to the project) andDIVIDE_DATA_PROVIDER=1in its environment. It must exit with 0 and print one JSON object, strict JSON (NaNandInfinityare refused). What it writes on standard error is shown in the diagnostics but not kept on disk. PHP's errors go to standard error, never into the data. - A provider entry that is not valid (a script outside the project, an unknown key, a time limit out of range) is reported, and its template has no data: it is not rendered with Div's convention instead.
-
examples/generatorhas one:tools/template-data.php.
It runs only when you ask. Run > Refresh template data runs the active template's provider once, under a progress box (Esc stops it and ends PHP). Nothing else runs it: not opening the project or the template, typing, completion, Run > Check, the render trace, nor the MCP server.
- Trust. The first refresh asks whether to trust the script, naming it with its arguments, the folder and the limits. It is real PHP with real effects on your computer: it is not a sandbox. Cancel is the first choice. The answer is kept in your own settings, never in the project, for that project and that script with those arguments; another script or other arguments ask again. Trusting Run, a Flow or a Mock Simulation does not trust a provider.
-
The snapshot. What the provider printed is kept as the template's snapshot in
.div/data-snapshots/(a.gitignorethere keeps it out of git). Ctrl+F9, the render trace (F7) and completion use it as the template's data. A snapshot made by another script or other arguments is never used. - No snapshot, no data. A template whose provider has no valid snapshot is not rendered with Div's convention or another file: divide says so and offers Refresh now.
- The script that runs is the one you saw. divide reads the script again just before starting PHP: if it changed since the question or the changes were shown, nothing runs. If it changes while PHP runs, the output is not kept. Files the script includes or reads are not checked: a provider is your project's own trusted code.
- When the script changes, the snapshot is stale: it is still used, with a warning, and the next refresh first shows what changed in the script.
- When a refresh fails (an exit code other than 0, output that is not one JSON object, the time limit, more than 5 MB of output, Esc, PHP that cannot be started, a snapshot that cannot be written), Messages says why, with PHP's errors at their place, and Output shows its standard error. The last valid data is kept.
- Run > Template data provider shows the provider, whether it is trusted and the state of its snapshot, and can Withdraw trust or Remove snapshot.
- Run > Edit data opens the provider's script. Run > Data file replaces the provider with a data file, and its Default button with Div's convention.
While the Output window is open, saving the template or its data re-renders in the background, without moving your focus and without the box (a spinner turns in the status line). Alt+F5 brings the Output window back; if there is none, it renders.
Div's own warnings, PHP notices and problems with the data go to the Messages window, below the template's checks. For example DATA: Div could not decode the data as an object; rendering without data when the JSON is broken; the data is decoded with Div's own jsonDecode(), so what you see is what the template gets.
One Div behaviour worth knowing: a data file is decoded before any variable exists, so $references inside page.json come out empty. divide adds a note when that happens. References do work in JSON inside templates, e.g. {= card: {"who": $person.name} =}.
See Installation: DIVIDE_DIV_PHP, the project's Div setup, Options > Div engine…, or the project's vendor/. When Div cannot be found, Ctrl+F9 tells you how to install it.
Div renders with the project's Div setup (.div/setup.json): its template folders, extensions, dialect, globals, functions and simulated request, as your application would set them up.
Debug > Render trace renders the same way and lets you replay every change Div made to the template, step by step, up to the fixed point where nothing changes any more. See Render Trace.
divide · part of Divengine · report an issue
Manual
- The Desktop
- Editing Templates
- Editing PHP
- Outline
- Finding Files and Commands
- Language Servers
- Completion
- Checking Templates
- Rendering
- Render Trace
- Running PHP
- Running Flows
- Flow Structure
- Flow Designer
- Flow Functions
- Flow Simulation
- Function Mock Simulation
- Debugging PHP
- Web Server
- Data Files
- Other Files
- Project Window
- Div Setup
- Dialector
- Translating Templates
- Composer
- Git
Reference
Links