Building Addons

An addon is how you can extend the core functionality of Statamic. Rather than digging in and messing with core files, we’ve created a system where developers can easily build new features that are compatible with everyone’s Statamic installations. Addons can then be easily shared or sold to others to let them extend their Statamic installation.

Regarding an Addon’s responsibility

Each Addon can be viewed as a new “feature”, or group of features, for your site. It can be something simple, such as a tag that returns the current time in Klingon, or something rather large, like an Ecommerce Shopping Cart. Although the complexity varies between the examples, each solves one clear problem.

If you’re in the need for a quick feature, you may consider creating a site helper. These are good place to throw a bunch of extensions without needing to go through creating a whole addon.

Assumed Knowledge

Statamic Addons involve writing PHP. While we have a lot of helper methods and API classes to take advantage of, you’ll still need to know how to write PHP, and be familiar with object oriented programming, PHP namespacing, and ideally - Laravel.

Addon Structure

An addon can contain a number of classes, each. It can be made up of one of them, or up to all of them. Each aspect accomplishes different missions.

  • Tags create tags for use within templates.
  • Modifiers are used in your templates to manipulate variables.
  • Fieldtypes create new ways to enter data into the Control Panel.
  • Event listeners can perform functionality when specific events are executed throughout the application.
  • Commands are used for executing functionality through the terminal.
  • Tasks allow you to schedule automated functionality at a predefined schedule.
  • Service Providers let you bootstrap functionality into the application.
  • API allows you to interact with other addons, and them with you.
  • Controllers allow you to create pages in the control panel.
  • Filters let you perform more complicated filtering of content on certain tags.
  • Widgets can be added to your Control Panel’s dashboard.

By using combinations of these aspects in your addons, you can create some truly fascinating results. And remember, all of these aspects are simply PHP, so anything you can do with PHP is possible here.

Not to mention, Statamic is built upon Laravel, so you can use any of Laravel’s features if you’d like.

So, what to tackle first? Let’s get started..

Last modified on December 14, 2017