Skip to content
  1. Extras
  2. Ace
  3. Integration

Integration ​

Plugin Ace listens to manager events: element forms, files, resource, resource overview cache tab, RTE registration, and TV input list.

Where the editor runs ​

ContextEvent / fieldDefault mime
SnippetOnSnipFormPrerender → modx-snippet-snippetPHP
PluginOnPluginFormPrerenderPHP
TemplateOnTempFormPrerenderace.html_elements_mime or auto
ChunkOnChunkFormPrerenderHTML/Fenom/Twig. Static chunks use the chunk name extension first, then the source file extension, otherwise text/plain
New fileOnFileCreateFormPrerendertext/plain, MODX tags off
Existing fileOnFileEditFormPrerenderby extension. An unknown extension uses the Ace mode for the file name, and MODX tags stay off
Resource (content)OnDocFormPrerender → #tacontent type. text/html is replaced with ace.html_elements_mime
Resource overview → cacheOnManagerPageBeforeRender → modx-rdata-bufferhtml mime
TVinput type Acealways text/html, MODX tags on

If which_element_editor is not Ace, the plugin returns immediately. The plugin does not initialize elements, files, the resource, the resource/data cache tab, or the TV list. OnRichTextEditorRegister runs earlier and still outputs the name Ace. An empty or missing setting counts as Ace.

Resources and RTE ​

  1. use_editor and which_editor respect the resource context.
  2. use_editor = No: Ace replaces #ta and every textarea with class modx-richtext (text/html, MODX tags on).
  3. use_editor = Yes and richtext, or class_key modStaticResource, modSymLink, modWebLink, modXMLRPCResource. Ace does not touch #ta. The plugin has no OnRichTextEditorInit handler.
  4. use_editor = Yes, richtext off, which_editor empty or Ace (case-insensitive): Ace on #ta.
  5. use_editor = Yes and which_editor is not Ace: #ta stays a plain textarea.
SetupSettings
Ace in content on every resourceuse_editor = No
Ace only on resources without richtextuse_editor = Yes, which_editor empty or Ace, richtext off
RTE for articles, textarea for code pagesuse_editor = Yes, another which_editor, richtext only where needed

Mime and MODX / Fenom highlighting ​

MODX tag highlighting is enabled only for HTML-like mimes:

  • text/html
  • text/x-smarty (Fenom / Smarty)
  • text/x-twig

For CSS/SCSS/LESS/static chunks with a .css extension, MODX mixed mode is off: // and /* */ comments highlight as CSS.

Auto ace.html_elements_mime when empty:

ConditionMime
twiggy_class presenttext/x-twig
pdotools_fenom_parser ontext/x-smarty
Otherwisetext/html

Set ace.html_elements_mime = text/x-smarty explicitly if Fenom in chunks is always required.

Extension of an existing file:

ExtensionMime
tpltext/x-smarty
htm, htmltext/html
csstext/css
scsstext/x-scss
lesstext/x-less
svgimage/svg+xml
xml, xslapplication/xml
jsapplication/javascript
jsonapplication/json
phpapplication/x-php
sqltext/x-sql
mdtext/x-markdown
txttext/plain
twigtext/x-twig

A new file is always text/plain. A static chunk checks the name extension first (header.css stays CSS even when the source file differs).

Saving PHP ​

For mime application/x-php and text/x-php, the editor does not replace the buffer after a snippet or plugin save. Condition: the only difference is the <?php / ?> wrapper. The undo history stays. MODX stores the code without that wrapper. After a reload the editor shows the database text, already without the wrapper. HTML chunks are not affected.

Tab snippets ​

ace.snippets format (Ace snippets):

text
snippet getr
    [[!getResources? &parents=`${1}` &limit=`${2:10}` &tpl=`${3}`]]

Ace definitions need a real Tab after the snippet name (Alt+09 in the setting), not spaces. The indent above is spaces for markdown only. Expand in the editor: name + Tab.

Default set (when ace.snippets is empty on install/upgrade): getr, getResources, pdoResources, pdoMenu, chunk, snippet, tv, formit, and more. Reference file: assets/components/ace/snippets/modx.default.snippets.

Add your own abbreviations in the system setting. Do not edit the assets file: package upgrades may overwrite it.

Completions ​

Ctrl+Space, Ctrl+Shift+Space, or Alt+Space. Request: assets/components/ace/completions.php. Actions: getFunctions, getProperties, getFilters, getObjects, getResourceFields. getFilters also offers snippets. getObjects returns chunks, snippets, TVs, and system settings. Resource fields are requested next to a TV.

Ace TV type ​

  1. Create a TV and choose input type Ace
  2. Assign the TV to a resource template

This type has no mime property. The field is always text/html with MODX tag highlighting. Height comes from the textarea style or is 200. ace.height does not apply to TVs.

Drafts ​

With ace.draft_restore = Yes, Ace writes field text to localStorage. After a reload Ace offers restore or discard. The banner stays hidden when the draft is empty or matches the text already open. Ace clears the draft in MODx.onSaveEditor when the field is already replaced by Ace. TTL: 7 days.