How does ExpressionEngine

Create your first ExpressionEngine plugin

No matter how great a CMS is, there are times when you need to meet a specific need that just doesn't work right away. Here's how to create plugins for ExpressionEngine to meet these needs.

Release Notes

Just recently, EllisLab, the developers of ExpressionEngine, announced the official release date of ExpressionEngine 2.0 as December 1, 2009. Please note that this tutorial was written with details on versions 1.6.x. Certain details such as file paths and global objects change for version 2.0. While these details are different, the general application and approach to plugin creation for ExpressionEngine remains the same.

Types of ExpressionEngine add-ons

Like most robust management systems, ExpressionEngine, or "EE", gives the developer several ways to add functionality that may not be standard. Unlike popular systems like WordPress, EE has different names for these add-ons depending on how they interact with your site. There are three main ways you can add functionality to EE 1.6.x such as: B. Plugins, extensions and modules. Plugins mainly deal with changing the template code and are more of a front-end job. Extensions usually optimize the functionality of the back-end or the control panel by adding "hooks" to the system. Modules are usually more extensive, have their own area in the control panel and can also be used in the front end of the EE website. Modules can be fully-fledged apps residing within EE using membership, templates, databases, etc.

Experience required

Things you should know for sure before proceeding:

  • Setting up and installing ExpressionEngine in a development environment
  • Basic understanding of the ExpressionEngine control panel and the analysis of templates
  • Basic knowledge of PHP and object-oriented programming
  • How do you read the documentation ?!

Our plugin

For this tutorial, we will create a simple plugin that will search the passed data and wrap certain strings with HTML tags. This is a very simple use of an EE plugin and should show you how easy it is to start plugin development. Our plugin is used to find and replace acronyms that we as developers use. For the example, we're going to stick to three: HTML, CSS, and RSS. Let's call the plugin "Auto Acronym".

Where should I start?

The best place to start when developing EE add-ons is from the official ExpressionEngine documentation. Before diving into the development of ExpressionEngine, be sure to read its guidelines, which, if followed, will help keep the system running well. The guidelines cover topics such as naming conventions, performance, and security. I'll give you a few minutes to read through the ExpressionEngine add-on development guidelines

Okay, now that you've read, we can take a look at how we create the plugins and what makes a simple plugin.

Pieces of the puzzle

Every plugin needs a class and at least one function. The naming convention is very specific, so we need to make sure that we do it correctly and carefully. The name of our plugin is Auto Acronym. It is used with our file name, class name and EE tags. The file name takes the name of your plugin and replaces all spaces with underscores if you put "pi" in front. Forward. All letters must be lowercase. That would make our filename "pi.auto_acronym.php". All EE plugins are stored in a single directory under system / plugins ..

The class name is similar to the file name except for the first letter, which is capitalized. This makes our class name "auto_acronym". This plugin only needs one function, so it has the same name as the class. These are also the names we use in our EE plugin tags. Plugin tags always start with "exp:", which tells the template parser, "Hey! I need some processing here!". Below is the name of your class in lower case: "exp: auto_acronym". The third segment of a plugin tag calls the function within the class of the plugin. In our example we only use one function, the constructor, so we only need the class name. This is how far we know about our plugin:

Put it in the code

Let's see what our code is so far: