Troubleshooting
I switched a field to Twig and there's no Craft autocomplete
This is a known limit. The CodeEditor library only sets up Craft API autocomplete when an editor
starts in Twig. If you switch a field's language picker to Twig after the page has loaded, you
get Monaco's Twig colours straight away, but not the craft. completions. Save and reload the
entry and they'll be there.
Fields whose language is fixed to Twig, and values already saved as Twig, get autocomplete from the start.
A CSS or JavaScript field shows no Craft completions
That's on purpose. Craft API completions are only offered in Twig fields. In a CSS field they would crowd out the property names Monaco does know, and generating them isn't free. Monaco's own completions for the language still work.
{kody:handle} in a rich-text field renders as nothing
Add :render, so the tag reads {kody:handle:render}. A Craft reference tag that names no property
falls back to the element's URL, and snippets don't have one. The snippet's edit screen shows the
exact tag to paste.
If the handle doesn't match any snippet, Craft leaves the tag in the text unchanged. That's how you
can tell a typo from a missing :render.
.eval() renders nothing
Check storage/logs/ for a warning from Kody. If it says the content was last saved by someone who
isn't an admin, that's the trust model working. You have three options:
- an admin re-saves the entry
- turn on Craft's
enableTwigSandbox(Craft 5.9+), so the code runs sandboxed whoever wrote it - accept that this entry's Twig doesn't run
Categories, globals and users keep no revisions, so Kody can't tell who last saved them. Without the sandbox, their Twig never runs. See Running code as Twig.
.eval() throws "Twig rendering is not enabled for this Kody field"
Both switches have to be on: Allow Twig rendering in the plugin settings (or
allowTwigRendering in config/kody.php), and the same setting on the field. Use
{% if entry.snippet.canEval() %} to guard a template that might run before both are on.
{% if entry.snippet %} is true for an empty field
A Kody value is an object, and Twig treats any object as true. Test entry.snippet.isNotEmpty
instead.
A language renders as plain text
Run:
php craft kody/languages/list
Languages marked editor only (CSV, log output and plain text) are edited with colours in the control panel but deliberately not highlighted on the page. For any other language, check that the stored language is the one you expect:
php craft kody/languages/check ./path/to/file.ext
check reports the language it resolved, the number of tokens, and a breakdown by type. If it says
"nothing matched" for a language that should highlight, that's a bug worth reporting.
Code over 256 KB is always rendered as plain text. Tokenising something that size on a page request isn't worth it.
My CSS changes to .kody don't apply
Kody's stylesheet sets the palette as custom properties on .kody. Override the properties
(--kody-bg, --kody-str, …) rather than the token classes. Or turn Include Kody's stylesheet
off and style the markup from scratch.
The highlighted output looks stale after an update
Highlighted HTML is cached by content, and Kody invalidates that cache itself whenever an update
changes the output. To clear it by hand anyway, use Utilities → Caches → Data caches, or set
cacheHighlighting to false in a dev environment.
The editor doesn't appear, just a textarea
Monaco loads from the CodeEditor library's asset bundle. Check the browser console for a failed
asset request, and make sure web/cpresources is writable. A Code field created inside a custom
control-panel template has to go through the field's own inputHtml. The editor is attached to the
namespaced input id, so markup assembled any other way gets no editor.