| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  | <?xml version="1.0" encoding="iso-8859-1"?> | 
					
						
							|  |  |  | <!-- $Revision$ --> | 
					
						
							|  |  |  |    <sect1 id="plugins.compiler.functions"><title>Compiler Functions</title> | 
					
						
							|  |  |  |     <para> | 
					
						
							|  |  |  |      Compiler functions are called only during compilation of the template. | 
					
						
							|  |  |  |      They are useful for injecting PHP code or time-sensitive static | 
					
						
							|  |  |  |      content into the template. If there is both a compiler function and a | 
					
						
							|  |  |  |      custom function registered under the same name, the compiler function | 
					
						
							|  |  |  |      has precedence. | 
					
						
							|  |  |  |     </para> | 
					
						
							|  |  |  |     <funcsynopsis> | 
					
						
							|  |  |  |      <funcprototype> | 
					
						
							|  |  |  |       <funcdef>mixed <function>smarty_compiler_<replaceable>name</replaceable></function></funcdef> | 
					
						
							|  |  |  |       <paramdef>string <parameter>$tag_arg</parameter></paramdef> | 
					
						
							|  |  |  |       <paramdef>object <parameter>&$smarty</parameter></paramdef> | 
					
						
							|  |  |  |      </funcprototype> | 
					
						
							|  |  |  |     </funcsynopsis> | 
					
						
							|  |  |  |     <para> | 
					
						
							|  |  |  |      The compiler function is passed two parameters: the tag argument | 
					
						
							|  |  |  |      string - basically, everything from the function name until the ending | 
					
						
							|  |  |  |      delimiter, and the Smarty object. It's supposed to return the PHP code | 
					
						
							|  |  |  |      to be injected into the compiled template. | 
					
						
							|  |  |  |     </para> | 
					
						
							|  |  |  |     <para> | 
					
						
							|  |  |  |      See also | 
					
						
							|  |  |  |      <link linkend="api.register.compiler.function">register_compiler_function()</link>, | 
					
						
							|  |  |  |      <link linkend="api.unregister.compiler.function">unregister_compiler_function()</link>. | 
					
						
							|  |  |  |     </para> | 
					
						
							|  |  |  |     <example> | 
					
						
							|  |  |  |      <title>simple compiler function</title> | 
					
						
							|  |  |  |      <programlisting role="php"> | 
					
						
							|  |  |  | <![CDATA[ | 
					
						
							|  |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  * ------------------------------------------------------------- | 
					
						
							|  |  |  |  * File:     compiler.tplheader.php | 
					
						
							|  |  |  |  * Type:     compiler | 
					
						
							|  |  |  |  * Name:     tplheader | 
					
						
							|  |  |  |  * Purpose:  Output header containing the source file name and | 
					
						
							|  |  |  |  *           the time it was compiled. | 
					
						
							|  |  |  |  * ------------------------------------------------------------- | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function smarty_compiler_tplheader($tag_arg, &$smarty) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ?> | 
					
						
							|  |  |  | ]]> | 
					
						
							|  |  |  | </programlisting> | 
					
						
							|  |  |  |      <para> | 
					
						
							|  |  |  |       This function can be called from the template as: | 
					
						
							|  |  |  |      </para> | 
					
						
							|  |  |  |      <programlisting> | 
					
						
							|  |  |  | {* this function gets executed at compile time only *} | 
					
						
							|  |  |  | {tplheader} | 
					
						
							|  |  |  |      </programlisting> | 
					
						
							|  |  |  |      <para> | 
					
						
							|  |  |  |       The resulting PHP code in the compiled template would be something like this: | 
					
						
							|  |  |  |      </para> | 
					
						
							|  |  |  |      <programlisting role="php"> | 
					
						
							|  |  |  | <![CDATA[ | 
					
						
							|  |  |  | <?php | 
					
						
							|  |  |  | echo 'index.tpl compiled at 2002-02-20 20:02'; | 
					
						
							|  |  |  | ?> | 
					
						
							|  |  |  | ]]> | 
					
						
							| 
									
										
										
										
											2004-04-14 15:53:39 +00:00
										 |  |  |      </programlisting> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |     </example> | 
					
						
							| 
									
										
										
										
											2004-04-14 15:53:39 +00:00
										 |  |  |    </sect1> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  | <!-- Keep this comment at the end of the file
 | 
					
						
							|  |  |  | Local variables: | 
					
						
							|  |  |  | mode: sgml | 
					
						
							|  |  |  | sgml-omittag:t | 
					
						
							|  |  |  | sgml-shorttag:t | 
					
						
							|  |  |  | sgml-minimize-attributes:nil | 
					
						
							|  |  |  | sgml-always-quote-attributes:t | 
					
						
							|  |  |  | sgml-indent-step:1 | 
					
						
							|  |  |  | sgml-indent-data:t | 
					
						
							|  |  |  | indent-tabs-mode:nil | 
					
						
							|  |  |  | sgml-parent-document:nil | 
					
						
							|  |  |  | sgml-default-dtd-file:"../../../../manual.ced" | 
					
						
							|  |  |  | sgml-exposed-tags:nil | 
					
						
							|  |  |  | sgml-local-catalogs:nil | 
					
						
							|  |  |  | sgml-local-ecat-files:nil | 
					
						
							|  |  |  | End: | 
					
						
							|  |  |  | vim600: syn=xml fen fdm=syntax fdl=2 si | 
					
						
							|  |  |  | vim: et tw=78 syn=sgml | 
					
						
							|  |  |  | vi: ts=1 sw=1 | 
					
						
							| 
									
										
										
										
											2004-04-14 15:53:39 +00:00
										 |  |  | --> |