Plain JavaScript, run via flutter_js. Decides which layout
partials actually get included when a PDF is
generated, and can prepare presentation data for blocks to use. Optional - a project
with nothing conditional doesn't need it. Edited via the Script
Editor. Runs after
validate.js passes - see the full processing
pipeline.
APIs available
| Name | Type | Meaning |
|---|---|---|
inputs |
object | Same submitted-data map validate.js sees. Assigning a new property onto it forwards that value to every block (see below); reassigning an existing submitted field's value has no effect. |
overlay(filename) |
function | Queues a layout partial (path relative to the project root) to be merged into this generation run. |
overlay("overlay.json"); // always include the base layout
if (inputs["is_certified"]) {
overlay("certified_badge.json"); // only when the checkbox is on
}
- If
process.jsdoesn't exist at all, the app behaves as if it contained exactlyoverlay("overlay.json");. - A partial named that doesn't exist is silently skipped, not an error.
- Every block
idacross everything actually included in one run must be unique.
Handing computed data to blocks
Compute presentation data here instead of writing a long formula inline in a block's
own JSON, by assigning it as a new property on inputs:
inputs.gridData = [];
for (var i = 0; i < inputs.options.length; i++) {
var option = inputs.options[i];
inputs.gridData.push(
{ text: (i + 1) + '. ' + option.description },
{ text: '$' + option.price, 'text-align': 'right' }
);
}
overlay("overlay.json");
(Turning a repeating group into grid cells specifically has its own walkthrough: Generating Grid Data.)
A block then references it directly:
{ "id": "options_grid", "type": "grid", "columns": 2, "data": "inputs.gridData" }
Two behaviors worth knowing:
- Only new property names get forwarded. Reassigning an existing submitted
field (e.g.
inputs.msrp = '$' + inputs.msrp) is silently dropped before rendering - a block still sees the original value. This is deliberate (the app's own date formatting, for example, would otherwise be bypassable). Always compute into a fresh name. process.jsand a block's own expression run in separate scripting contexts - the only bridge between them is a newinputs.*property. A plain local variable (var x = 5;) never reaches a block.