--- layout: default title: Mentions plugin title_nav: Mentions description: Enables @mention functionality. keywords: mentions atmentions --- The mentions plugin will present a list of users when a user types the "@" symbol followed by the beginnings of a username after it. It will then query your server using the `mentions_fetch` callback. ##### Example {% include codepen.html id="mentions" height="400" %} ## Options These configuration options affect the execution of the `mentions` plugin. The main option that needs to be implemented is the `mentions_fetch` callback. ### `mentions_fetch` This option lets you request a list of uses from your server that match a search query. The callback gets passed two parameters: one is the search query object, the other is the success callback to execute with the results. The query object has a term property that contains what the user has typed after the "@" sign. The success call should contain an array of users with the required properties "id" and "name". **Type:** `function` **Default Value:** `none` ##### Example ```js var usersRequest = null; tinymce.init({ selector: "textarea", plugins: "mentions", mentions_fetch: function (query, success) { // Fetch your full user list from the server and cache locally if (usersRequest === null) { usersRequest = fetch('/users'); } usersRequest.then(function(users) { // query.term is the text the user typed after the '@' users = users.filter(function (user) { return user.name.indexOf(query.term.toLowerCase()) !== -1; }); users = users.slice(0, 10); // Where the user object must contain the properties `id` and `name` // but you could additionally include anything else you deem useful. success(users); }); } }); ``` **Note:** *The values returned in the users array for "id" and "name" all need to be* `String` *values* ### `mentions_menu_complete` This option overrides the default logic for inserting the mention into the editor. The callback should return an element created using the editor's document. **Type:** `function` **Default Value:** `none` ##### Example ```js tinymce.init({ selector: "textarea", plugins: "mentions", mentions_selector: 'span.mymention', mentions_menu_complete: function (editor, userInfo) { var span = editor.getDoc().createElement('span'); span.className = 'mymention'; // store the user id in the mention so it can be identified later span.setAttribute('data-mention-id', userInfo.id); span.appendChild(editor.getDoc().createTextNode('@' + userInfo.name)); return span; } }); ``` ### `mentions_menu_hover` This option enables you to provide an element to present next to the menu item being hovered. This lets you do custom UIs for presenting user information. **Type:** `function` **Default Value:** `none` ##### Example ```js var userRequest = {}; tinymce.init({ selector: "textarea", plugins: "mentions", mentions_menu_hover: function (userInfo, success) { // request more information about the user from the server and cache it locally if (!userRequest[userInfo.id]) { userRequest[userInfo.id] = fetch('/user?id=' + userInfo.id); } userRequest[userInfo.id].then(function(userDetail) { var div = document.createElement('div'); div.innerHTML = ( '
' + userDetail.description + '
' + '' + userDetail.description + '
' + '