Creating a Simple Expression Engine Plugin
Expression Engine is usually great, but I think we all wish there was either more support for advanced PHP functions, or PHP wasn’t such a mess to work with within templates files. I also find plugins for simple things discouraging- after a while you end up with a long list of miscellaneous plugins which is a maintenance disaster waiting to happen.
My solution to getting around all of these issues in Expression Engine is to simply toss in a plugin, and add what I need to it. In Expression Engine 2, plugins live in “system/expressionengine/third_party” and require a folder name that matches the plugin name.
I just named my plugin the name of my company, so it is easy to distinguish, so I first created a folder “prime” with the “third_party” folder. Next, I added a file name “pi.prime.php” to the “prime” folder. The plugin itself is a PHP class exposed to Expression Engine by a tag pair, formatted as “{exp:class:function}tagdata{/exp:class:function}”.
Once the file is created, it is accessible in your templates and you can starting making magic.
{exp:prime:no_spaces}Holy crap this is easy!{/exp:prime:no_spaces}
result → Holycrapthisiseasy!
{exp:prime:format_phone}6509636889{/exp:prime:format_phone}
result → (650) 963-6889
{exp:prime:strip allow="<span>"}<p>This section is <strong>super</strong> awesome and <span>amazingly simple</span></p>{/exp:prime:strip}
result → This section is super awesome and <span>amazingly simple</span>
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011