DocsCode Snippets

Variables, secrets, versions and logs

Keep values and encrypted secrets out of your code, compare and restore versions, and read what every snippet logged.

Variables#

Plain values you manage in Code Snippets → Variables and use anywhere:

$limit = nai_var('POSTS_LIMIT');   // in PHP
<p>Call {{var:PHONE}}</p>          <!-- in HTML, CSS and JavaScript snippets -->

Secrets#

API keys and tokens your PHP snippets need. Secrets are encrypted at rest and readable only by PHP:

$key = nai_secret('MAPS_API_KEY');
  • They’re never shown after saving, never returned by the API, never exported, never sent to the AI, and redacted from logs.
  • Putting a secret into browser code (JavaScript, HTML, CSS) is refused.
  • Managing them needs the Manage snippet secrets permission.

Versions#

Every save and activation is a version. Compare any two side by side, restore one into your working copy, or use Restore the last working version to put the previous live version back.

Logs#

Each snippet’s log — and Code Snippets → Logs for all of them — shows fatal errors, exceptions, JavaScript errors from visitors’ browsers, failed API calls, activations, tests, runs and safe mode, with credentials redacted. Write your own entries with nai_log().

Setting (Settings → Code snippets)Default
Log snippet errors and activityOn (fatal errors and shut-offs are always logged)
Keep snippet logs for (days)30
Email the site admin when a snippet is turned off after a fatal errorOn

Performance#

One request in 50 is timed for each snippet version, so the snippet shows its average and slowest run.

Permissions#

PermissionAllows
See code snippetsOpen Code Snippets and read every snippet’s code and settings.
Edit code snippetsChange code and settings (saving never changes what runs).
Add code snippetsCreate, duplicate and import snippets — always as drafts.
Activate code snippetsTurn snippets on and off and make changes live.
Write and run PHPEdit, test, activate and run PHP snippets.
Manage snippet secretsAdd and change encrypted values.
See snippet logsRead and clear errors and activity.