Moodle Plugins directory: Snippet for TinyMCE | Moodle.org

Snippet for TinyMCE
TinyMCE ::: tiny_snippet
Maintained by
Justin Hunt
Tiny Snippet is simple html/text template tool for Moodle's Tiny editor. Use it to add text, layouts, buttons and other content from templates directly into Moodle HTML areas.
Latest release:
203 sites
117 downloads
3 fans
Current versions available: 1
Snippet is a template solution for Moodle content creation. Templates and variables(placeholders) are declared in the admin settings for the plugin. When the icon is click on the Tiny editor, the user can choose the template and the values for each of the variables. The placeholders and template are then merged to create the final content which is then inserted on the page.
Snippet has no filter plugin companion. It returns html directly to the text area. This is useful when the content doesn't need javascript, and has the benefit that the content is instantly visible and editable in the text area (ie without filtering). As an example of this, the Youtube template will display a Youtube video in the html editor text area immediately.
To make a snippet, find an empty snippet template page in the plugin's admin settings, site admin -> plugins -> text editors -> TinyMCE Editor -> Snippet for TinyMCE -> Snippets. Enter a name for the snippet, the content of the snippet and any default variable values. Variables can be used in the snippet content and are surrounded by {{ or }} marks. Like this: {{bigvariable}}

sweety
Snippet
My sweet food on {{weekday}} is: {{mysweety}}
Defaults
mysweety=candy,weekday=Monday
This could display as:
My sweet food on Thursday is: cake
If you run out of blank snippet templates, you can always create more. Set the number of snippets on the settings page.
Site admin -> Plugins -> Text editors -> TinyMCE -> Snippet for TinyMCE

If you wish your exported template to appear in the presets dropdown you must place the .txt file in the presets folder under /lib/editor/tiny/plugins/snippet.
If using zip, first download and unzip the file, and place the snippet folder in your Moodle's /lib/editor/tiny/plugins folder. Or use git directly from the /lib/editor/tiny/plugins folder, ie
git clone https://github.com/justinhunt/moodle-tiny_snippet.git snippet
Then visit your site admin's notifications page. The plugin installer will walk through the installation process. At the end you will see a list of templates. You can leave them for now and fill them in later. 3 of the templates are blank, and a helloworld and a youtube template are automatically created for you.
Snippet has no filter plugin companion. It returns html directly to the text area. This is useful when the content doesn't need javascript, and has the benefit that the content is instantly visible and editable in the text area (ie without filtering). As an example of this, the Youtube template will display a Youtube video in the html editor text area immediately.
Using Snippet
To use a snippet, look for the half-page icon on the text editor. Checking on that should open the Snippet dialog with a button for each snippet.To make a snippet, find an empty snippet template page in the plugin's admin settings, site admin -> plugins -> text editors -> TinyMCE Editor -> Snippet for TinyMCE -> Snippets. Enter a name for the snippet, the content of the snippet and any default variable values. Variables can be used in the snippet content and are surrounded by {{ or }} marks. Like this: {{bigvariable}}

An example snippet:
Snippet Namesweety
Snippet
My sweet food on {{weekday}} is: {{mysweety}}
Defaults
mysweety=candy,weekday=Monday
This could display as:
My sweet food on Thursday is: cake
If you run out of blank snippet templates, you can always create more. Set the number of snippets on the settings page.
Site admin -> Plugins -> Text editors -> TinyMCE -> Snippet for TinyMCE
Presets
There is a dropdown list of presets at the top of each snippet settings page. These will fill the template page in with the details of a preset template. You can make your own presets and share them too. To do this you can the template by mouse clicking on the green "bundle" box on the top right of the template settings page. It will download as a .txt file. Drag an exported .txt file over the green bundle box on a blank template settings page to import it.
If you wish your exported template to appear in the presets dropdown you must place the .txt file in the presets folder under /lib/editor/tiny/plugins/snippet.
Installation
This plugin is for Moodle TinyMCE v6 (Moodle 4.1 or greater). You can install directly from this page if the "Install" button appears on the page top right.If using zip, first download and unzip the file, and place the snippet folder in your Moodle's /lib/editor/tiny/plugins folder. Or use git directly from the /lib/editor/tiny/plugins folder, ie
git clone https://github.com/justinhunt/moodle-tiny_snippet.git snippet
Then visit your site admin's notifications page. The plugin installer will walk through the installation process. At the end you will see a list of templates. You can leave them for now and fill them in later. 3 of the templates are blank, and a helloworld and a youtube template are automatically created for you.
Useful links
Contributors
Justin Hunt (Lead maintainer)
Please login to view contributors details and/or to contact them
Comments