An example plugin for Craft CMS
Switch branches/tags
Nothing to show
Latest commit baac7a9 Apr 18, 2013 @amacneil Merge pull request #4 from lukeholder/patch-1
Fixed Namespaced call of Admintable
Failed to load latest commit information.
controllers updated templates & controllers for Craft Mar 12, 2013
models Craft! Mar 6, 2013
records Craft! Mar 6, 2013
services Craft! Mar 6, 2013
tests Craft! Mar 6, 2013
twigextensions Craft! Mar 6, 2013
variables Craft! Mar 6, 2013
LICENSE.txt Initial commit Nov 26, 2012 Craft! Mar 6, 2013
composer.json Craft! Mar 6, 2013
phpunit.xml.dist Craft! Mar 6, 2013

Cocktail Recipes Plugin for Craft CMS

This is an example plugin for the Craft CMS Beta, inspired by the documentation. It is well documented, and designed to get you up and running quickly, by giving you a working example to start developing from.

The plugin adds an ingredients table to the database, with custom control panel pages to add new ingredients. It also adds an Ingredients fieldtype, which can be added to your sections or pages.

Obviously there are many things in this plugin which could be done differently for a plugin this simple. However, we prefer to do things the most complete way possible, to give you a non-trivial working example.


  1. Upload this directory to craft/plugins/cocktailrecipes/ on your server.
  2. Enable the plugin under Craft Admin > Settings > Plugins


Cocktail Recipes provides examples of the following Craft components:

  • Ingredients Fieldtype (allows user to select from available ingredients)
  • Controller (handles template actions)
  • Ingredients Model (read only data object)
  • Ingredients Record (database definition and write access)
  • Service (provdes API to create/save/delete ingredients)
  • Templates (provides custom control panel section)
  • Twig Extension (provides shake twig filter)
  • Variables (provides read only API to access ingredients from within templates)

Craft provides many extension points, and more examples will be added in future (pull requests accepted).

Unit Tests

In addition, a PHPUnit test suite is provided to ensure all components are behaving correctly. To run the tests, run the following commands:

cd plugins/cocktailrecipes
composer update --dev

Coding Standards

All code follows the standard PHP PSR-2 coding style guide. This is being adopted by a large number of PHP frameworks, to ensure consistency in the PHP community. The coding style can easily be verified/fixed by running php-cs-fixer.


This work is licenced under the MIT license.