This is a utility module. The goal it to provide a simple UI to allow content
creators to append arbitrary javascript snippets to pages. It provides an
Object Oriented wrapper around drupal_add_js that gives a simple UI for creating
and storing a snippet or a series of snippets.
*NOTICE*
By its very nature, this module is a security risk. Please note that this
module will allow users to append arbitrary unfiltered javascript and other
markup to any page. If not used with caution, this module can break or
compromise your site.
This module uses the Entity API module to store snippets as entities.
You can deploy your snippets in several ways:
* via text filter, a WYSIWYG plugin has been provided (tested with tinyMCE). The Snippet Filter uses tokens in the format of [{[js_snippet:1:Snippet%20Title]}]
* via designating snippets to be available as blocks to be used site wide, then using this block on a page, view, or panel.
* in code, using alter hooks. It can also be a useful developer tool. You can easily create snippets for frequently used combinations and attach them to elements or .
<?php
function hook_form_alter(&$form, &$form_state) {
// Load your snippet
$snippet = js_snippets_load(1);
// Fully rendered HTML with javascripts added via drupal_add_js
$form['my_snippet']['#markup'] = $snippet->asHtml();
// OR