Code per Node makes it possible to add custom CSS and Javascript per node, per content type, per block, and globally. The code is stored in the database, but served from the file system. It also supports syntax highlighting with CodeMirror.
CPN was covered by a recent webinar by Mediacurrent: http://www.mediacurrent.com/blog/webinar-code-node (this is also mentioned in DrupalEasy podcast 120)
It should be made clear that allowing non-developers to insert JS at will can be A Really Bad Idea; to quote Bob Kepford:
That sad moment when I consider just using Code per Node.
Installation
After the usual module installation, you should:
- Configure the global settings at
admin/config/content/cpn
(D7) oradmin/settings/cpn
(D6). - Set appropriate permissions at
admin/people/permissions
(D7) oradmin/user/permissions
(D6). - Enable per-content type settings at
admin/structure/types/manage/[node-type]
(D7) oradmin/content/node-type/[node-type]
(D6).
Optional:
- Install CodeMirror (tested with v3.20) to
sites/all/libraries/codemirror
. - Turn on syntax highlighting at
admin/config/content/cpn
(D7) oradmin/settings/cpn
(D6).
Additional Notes
- CPN has only been tested with CodeMirror v3 (specifically v3.20), may not work with the new v4 (see #2292521).
- While the priority is the D7 version, effort is being made to backport all improvements to D6 too.
- The 6.x-1.x and 7.x-1.x branches both support Libraries API for the installation of CodeMirror.
- An excellent tutorial has been written by Jeff Geerling that explains how to migrate from inline CSS/JS in the node body into CPN.
Related Modules
This module provides functionality similar to other modules. I'll outline the differences, as I best understand them:
- CSS Injector: doesn't support Javascript (though JS Injector does); doesn't provide fields for CSS per-node, though it may be possible in the admin settings via configurable rules (and may get implemented in #437006: Added CSS fieldset for node/edit); doesn't support CSS per-block.
- CSS: doesn't serve the CSS from the file system; doesn't support Javascript; doesn't support CSS per-block.
- Context Add Assets: doesn't support editing CSS or Javascript through the website; association of external assets happens in the backend Context module; doesn't support per-block assets.
- Inline CSS Checker: use this to find any content that has inline CSS in text fields.
Credits
Originally build by joelstein, Rob Loach contributed on the D7 port. Currently maintained by Damien McKenna.
Continued development is sponsored by Mediacurrent.
Project information
- Module categories: Developer Tools
- 1,797 sites report using this module
- Created by joelstein on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Fixes two glaring bugs in 1.6.
Development version: 7.x-1.x-dev updated 6 Jul 2016 at 20:22 UTC