<HTML ><HEAD ><TITLE >Extending Smarty With Plugins</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Smarty For Programmers" HREF="smarty.for.programmers.html"><LINK REL="PREVIOUS" TITLE="Resources" HREF="template.resources.html"><LINK REL="NEXT" TITLE="Naming Conventions" HREF="plugins.naming.conventions.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="chapter" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="template.resources.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="plugins.naming.conventions.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="plugins" ></A >Chapter 16. Extending Smarty With Plugins</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="plugins.html#plugins.howto" >How Plugins Work</A ></DT ><DT ><A HREF="plugins.naming.conventions.html" >Naming Conventions</A ></DT ><DT ><A HREF="plugins.writing.html" >Writing Plugins</A ></DT ><DT ><A HREF="plugins.functions.html" >Template Functions</A ></DT ><DT ><A HREF="plugins.modifiers.html" >Modifiers</A ></DT ><DT ><A HREF="plugins.block.functions.html" >Block Functions</A ></DT ><DT ><A HREF="plugins.compiler.functions.html" >Compiler Functions</A ></DT ><DT ><A HREF="plugins.prefilters.postfilters.html" >Prefilters/Postfilters</A ></DT ><DT ><A HREF="plugins.outputfilters.html" >Output Filters</A ></DT ><DT ><A HREF="plugins.resources.html" >Resources</A ></DT ><DT ><A HREF="plugins.inserts.html" >Inserts</A ></DT ></DL ></DIV ><P > Version 2.0 introduced the plugin architecture that is used for almost all the customizable functionality of Smarty. This includes: <P ></P ><UL COMPACT="COMPACT" ><LI ><SPAN >functions</SPAN ></LI ><LI ><SPAN >modifiers</SPAN ></LI ><LI ><SPAN >block functions</SPAN ></LI ><LI ><SPAN >compiler functions</SPAN ></LI ><LI ><SPAN >prefilters</SPAN ></LI ><LI ><SPAN >postfilters</SPAN ></LI ><LI ><SPAN >outputfilters</SPAN ></LI ><LI ><SPAN >resources</SPAN ></LI ><LI ><SPAN >inserts</SPAN ></LI ></UL > With the exception of resources, backwards compatibility with the old way of registering handler functions via register_* API is preserved. If you did not use the API but instead modified the class variables <TT CLASS="literal" >$custom_funcs</TT >, <TT CLASS="literal" >$custom_mods</TT >, and other ones directly, then you will need to adjust your scripts to either use the API or convert your custom functionality into plugins. </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="plugins.howto" ></A >How Plugins Work</H1 ><P > Plugins are always loaded on demand. Only the specific modifiers, functions, resources, etc invoked in the templates scripts will be loaded. Moreover, each plugin is loaded only once, even if you have several different instances of Smarty running within the same request. </P ><P > Pre/postfilters and output filters are a bit of a special case. Since they are not mentioned in the templates, they must be registered or loaded explicitly via API functions before the template is processed. The order in which multiple filters of the same type are executed depends on the order in which they are registered or loaded. </P ><P > The <A HREF="variable.plugins.dir.html" >plugins directory</A > can be a string containing a path or an array containing multiple paths. To install a plugin, simply place it in one of the directories and Smarty will use it automatically. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="template.resources.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="plugins.naming.conventions.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Resources</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="smarty.for.programmers.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Naming Conventions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >