# mod\_editor\_tinymce

Source: https://zotonic.com/docs/1756/mod_editor_tinymce

URI: https://zotonic.com/id/1756

Language: en



Adds wysiwyg tinyMCE editors to the admin.

The module packs various versions, the version to be used can be selected on the `/admin/modules` page.

Two additional tinyMCE plugins are added:

- The plugin `zmedia` for selecting images, videos and other media items. In a dialog the centering, size, and optional caption can be choosen. The selected media are added to the page with a `depiction` connection.
- The plugin `zlink` for adding links (`<a href="...">...</a>`) to Zotonic pages in the edited text. The title and URL to the page are automatically added.

Media are added as HTML comments in the body text. The filter <a href="/id/doc_template_filter_filter_show_media" class="doc-reference doc-reference-filter"><code>filter#show_media</code></a> is used to translate the HTML comment into a figure or other tags. This is done using the template `_body_media.tpl`, though other templates can also be used.

Usage
-----

Use TinyMCE by incluyding `_editor.tpl` in your template.

This will, after page load, check all textarea tags with the class `z_editor-init`. These textarea tags are then augmented with a TinyMCE editor.

Call the JavaScript function `tinymce.triggerSave();` to save all the TinyCME editor instances to their textarea tags. A wired submit action will save before submitting the form.

Options
-------

All TinyMCE options are set in the global object `tinyInit`. This is done by the `tiny-init.js` file inside the version of TinyMCE. For example `priv/lib/js/tinymce-5.10.2/tiny-init.js`

This file is included by `editor.tpl`, which should be included in your template if you want to use the editor.

Supply your own `tinyInit` object to change the default settings. This can be done before the include of `_editor.tpl`, as the `tiny-init.js` will not replace any existing `tinyInit` object.

Stylesheet
----------

The default TinyMCE `tiny_init.js` included by `_editor.tpl` includes a stylesheet from `/lib/css/tinymce-zotonic.css`.

By adding a file `priv/lib/css/tinymce-zotonic.css` in your site or module it is possible to use your own styles for the editor.

Takes care of adding the styles for the images managed by the `zmedia` plugin. The default image styles are:

```css
img.z-tinymce-media {
    position: relative;
    border: 1px solid #667;
    height: auto;
    cursor: pointer;
    width: 270px;
}

img.z-tinymce-media.z-active:hover {
    border: 1px solid #039ed4;
}

img.z-tinymce-media-align-block {
    display: block;
    margin: 1rem 0;
    clear: both;
}

img.z-tinymce-media-align-right {
    float: right;
    margin: 0.5rem;
}

img.z-tinymce-media-align-left {
    float: left;
    margin: 0.5rem;
}

img.z-tinymce-media-size-large {
    width: 90%;
}

img.z-tinymce-media-size-middle {
    width: 50%;
}

img.z-tinymce-media-size-small {
    width: 25%;
}
```

Accepted Events
---------------

Delegate callbacks:

- `event/2` (no explicit `#postback/ #submit/ #postback_notify` message clauses documented in this module).

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1756?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1756?language=en>)
