5. Snippets


The content for pages in Page module will be added using WYSIWYG (what you see is what you get) editor (CKEditor). Sometimes for some parts of the text on a webpage it is needed to format it in custom way, while the rest of the page can be formatted as CKEditor does it. In such cases using CKEditor only is very complicated. Here is where snippets come into play.

By using snippets of Allmice CMS page modules, the page editor writes a token or many tokens (called also snippet code) to the webpage content into places, where he/she wishes the custom text or PHP code output (snippet) to be displayed. View event of the Page module replaces then every such token with the plain text/html code (or with by PHP code provided text or html code), which the editor (or developer of a module) has related to the corresponding snippet code. The snippet codes are small unique strings (chosen and entered by editor's discretion), which are different from any other part of the the page content (otherwise such text would be replaced where it is not meant to be replaced).

You can add snippet codes, when you are editing pages - there will be a corresponding "add snippet" link, when you are editing a page.

There are four types of snippets:
1) Plain text local
2) PHP code local
3) Plain text global
4) PHP code global

Unless you are a developer, you probably need to use local plain text snippets only.

The difference between local and global snippets is, that local snippets can be related to one page only, whereas global snippets can be used on every page.
It may be a bit slower (more memory consuming) to use global snippets, because all the global snippets will be read into memory for every page, whereas local snippets will be read into memory only if related to the current page.

Classic Edition Page module and OwnPage module methods are providing functionality to add/edit/delete local snippets (which are recorded in table mod_page_snippet in database). You should start to edit a page first and then you would have links to manage snippets related to this page.
Global snippets are meant to be first of all recorded into database automatically by installing a module, which uses them. For example an e-commerce module may use PHP code global snippets to show quantity, price, etc. for every product page. Modules may be provided to manage global snippets also manually. Global snippets are recorded into core_misc_data table. You can use SystemManager module *TsvSet methods to manage global snippets through Allmice CMS user interface.

Previous: 4. Managing own Pages, Snippets and Posts | Next: 6. Comments (Posts)
Pages, Snippets, Posts
1. Add a page
2. List, view, edit or delete Pages
3. Managing Pages by different roles
4. Managing own Pages, Snippets and Posts
5. Snippets
6. Comments (Posts)