Modules
From Snapp CMS Developer Documentation
Modules are responsible for the processing and rendering of pages in SnappCMS. There is one module for each "Page Type" that a user can create.
Contents |
Available Modules
SnappCMS supplies a large range of Built-in Modules.
If however you can't find a module that suits your requirements, you can always Build your own.
Structure
Modules are broken up into MVC layers to separate presentation logic from application logic. Each layer is explained below.
Model
The core of a model in Snapp is implemented by the "module" classes (e.g. moduleContent, moduleBlog, etc). These contain all of the application logic for manipulating and outputting data related to the page types used by your website.
The module model class is called by the module controller and sends its output to the module view.
SnappCMS module model classes reside in the /cms/modules folder. Custom site-specific model classes reside in DOCUMENT_ROOT/custom/
View
Module views are grouped into templates, and each template folder contains the actual view files for each module controller action.
Templates
Modules can have multiple templates associated with them.
For example, you may create two "Blog" pages on your site. You may wish one of these to actually run as a blog, with a traditional appearance of articles listed most recent first going down the page, and a list of categories down one side. Hence, you could create a template named traditional which contains all the view files for this layout.
You may also want another page may be for press releases, which you want to display in a multi-column format. You could create another template named press_releases containing all the code to lay out your press release pages in this format.
By creating multiple templates for your blog module, you can use the same module to render these different looking pages. Module templates are located in DOCUMENT_ROOT/modules/MODULE_NAME/templates/TEMPLATE_NAME/
Each template must contain:
- a
template.infofile, which specifies the template's metadata that is used by the administration system when admins wish to select between multiple templates for a given page. - View files for each module controller action (as defined in
DOCUMENT_ROOT/modules/MODULE_NAME/index.php)
View Files
There is also a PHP view file for each action associated with the module's controller, and asset folders (images, css, js) for the template.
e.g. the default template for the Blog module resides in
DOCUMENT_ROOT/modules/content/templates/default/
and is comprised of the following files:
article.php
| For displaying a single article |
articles.php
| For displaying a group of articles |
index.php
| For displaying the blog's main page |
template.info
| Metadata for the template |
Controller
The controllers implemented as index.php files in each module directory controlling what data is loaded and which rendering template is used to display the data.
e.g. the controller for the module which displays plain static content pages is located in DOCUMENT_ROOT/modules/content/index.php
