Installation
Requirements
- Craft CMS 5.3 or later
- PHP 8.2 or later, with the
jsonandmbstringextensions
Kody pulls in one library, nystudio107's CodeEditor, which bundles Monaco and supplies the Twig and Craft API autocomplete. It is a Yii extension rather than a plugin, so there is nothing else to install or switch on.
Kody makes no outbound HTTP requests, ever.
Installing
composer require justinholtweb/craft-kody
php craft plugin/install kody
Installing creates one table, kody_snippets, for the snippet library. It adds no fields and
changes nothing on your site's front end until a template asks it to.
It's free
There are no editions, no licence key and no licensing code in the plugin. Every feature on this site is in the version you just installed.
Your first field
- Settings → Fields → New field, and pick Code.
- Choose a language. Always the same language suits a field like "Custom CSS"; The author chooses suits a "Code sample" field, and puts a language picker above the editor.
- Add the field to a field layout and open an entry. That's Monaco: the editor from VS Code.
Then print it from a template:
{{ entry.mySnippet.render() }}
That one call returns the highlighted block, with its caption and copy button. The highlighting happens on the server, so the page doesn't need any JavaScript for it.
Upgrading from craft3-codemirror
luwes/craft3-codemirror stopped at Craft 3 and has no Craft 5 version, so there is nothing to
migrate in place. Create a Kody field, copy the content across, and point your templates at
.render(). Kody stores a field's value as code and language keys rather than a plain string.
A template that printed the old field directly still works, though, because a Kody value prints as
its source.