Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An example plugin for Craft CMS
Latest commit baac7a9 @adrianmacneil 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
fieldTypes Craft!
models Craft!
records Craft!
services Craft!
templates Fixed Namespaced call of Admintable
tests Craft!
twigextensions Craft!
variables Craft!
.gitignore Craft!
CocktailRecipesPlugin.php updated templates & controllers for Craft
LICENSE.txt Initial commit Craft!
composer.json Craft!
phpunit.xml.dist Craft!

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.

Something went wrong with that request. Please try again.