Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcTemplateCustomFunctionDefinition

Template::ezcTemplateCustomFunctionDefinition

Class ezcTemplateCustomFunctionDefinition

Contains the definition of a custom function.

Example of use: create a function to hide a mail address.

  1. Create a class which implements ezcTemplateCustomFunction and which
will be included in your application (with the autoloading mechanism).
  1.  class htmlFunctions implements ezcTemplateCustomFunction
  2.  {
  3.      public static function getCustomFunctionDefinition( $name )
  4.      {
  5.          switch ($name )
  6.          {
  7.              case "hide_mail":
  8.                  $def = new ezcTemplateCustomFunctionDefinition();
  9.                  $def->class = __CLASS__;
  10.                  $def->method = "hide_mail";
  11.                  $def->parameters = array( "mailAddress" );
  12.                  return $def;
  13.          }
  14.          return false;
  15.      }
  16.  
  17.      public static function hide_mail( $mailAddress )
  18.      {
  19.          $old = array( '@', '.' );
  20.          $new = array( ' at ', ' dot ' );
  21.          return  str_replace( $old, $new, $mailAddress );
  22.      }
  23.  }

2. Assign the class to the Template configuration in your application.

  1.  $config->addExtension( "htmlFunctions" );

3. Use the custom function in the template.

  1.  {hide_mail( "john.doe@example.com" )}
The generated html code for this will be: john dot doe at example dot com

Source for this file: /Template/src/structs/custom_function_definition.php

ezcTemplateCustomExtension
   |
   --ezcTemplateCustomFunctionDefinition
Version:   //autogen//

Member Variables

public string $class
Holds the (static) class that implements the function to be executed.
public string $method
Holds the (static) method that should be run.
public array(string) $parameters = array()
Holds the required and optional named parameters for this custom function.

The optional parameters should be specified after the required parameters.

  • Required parameters are named strings.
  • Optional parameters are named strings enclosed with square brackets.
public bool $sendTemplateObject = false
Whether or not the Template object is available in the custom function.

Be aware that if you change this, your custom function's signature changes as the first argument will then be the template object.

public bool $variableArgumentList = false
Whether or not the custom function can have an undefined amount of parameters.

The maximum amount of parameters check will be omitted. The custom function implementation will most probably use PHP function: func_get_args() or simular.

Documentation generated by phpDocumentor 1.4.3