public function template($code=null, $context=null) {
    list($code, $context) = self::_wrapArgs(func_get_args(), 2);

    $class_name = __CLASS__;
    
    $return = self::_wrap(function($context=null) use ($code, $class_name) {
      $ts = $class_name::getInstance()->_template_settings;
      
      // Wrap escaped, interpolated, and evaluated blocks inside PHP tags
      extract((array) $context);
      preg_match_all($ts['escape'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . ' echo htmlentities(' . trim($var[1]) . '); ' . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      preg_match_all($ts['interpolate'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . ' echo ' . trim($var[1]) . '; ' . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      preg_match_all($ts['evaluate'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . trim($var[1]) . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      $code = str_replace($class_name::TEMPLATE_OPEN_TAG, '<?php ', $code);
      $code = str_replace($class_name::TEMPLATE_CLOSE_TAG, '?>', $code);
      
      // Use the output buffer to grab the return value
      $code = 'ob_start(); extract($context); ?>' . $code . '<?php return ob_get_clean();';
      
      $func = create_function('$context', $code);
      return $func((array) $context);
    });
    
    // Return function or call function depending on context
    return self::_wrap(((isset($this) && isset($this->_wrapped) && $this->_wrapped) || !is_null($context)) ? $return($context) : $return);
  }
public function template($code=null, $context=null) {
    list($code, $context) = self::_wrapArgs(func_get_args(), 2);

    $class_name = __CLASS__;
    
    $return = self::_wrap(function($context=null) use ($code, $class_name) {
      $ts = $class_name::getInstance()->_template_settings;
      
      // Wrap escaped, interpolated, and evaluated blocks inside PHP tags
      extract((array) $context);
      preg_match_all($ts['escape'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . ' echo htmlentities(' . trim($var[1]) . '); ' . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      preg_match_all($ts['interpolate'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . ' echo ' . trim($var[1]) . '; ' . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      preg_match_all($ts['evaluate'], $code, $vars, PREG_SET_ORDER);
      if(count($vars) > 0) {
        foreach($vars as $var) {
          $echo = $class_name::TEMPLATE_OPEN_TAG . trim($var[1]) . $class_name::TEMPLATE_CLOSE_TAG;
          $code = str_replace($var[0], $echo, $code);
        }
      }
      $code = str_replace($class_name::TEMPLATE_OPEN_TAG, '<?php ', $code);
      $code = str_replace($class_name::TEMPLATE_CLOSE_TAG, '?>', $code);
      
      // Use the output buffer to grab the return value
      $code = 'ob_start(); extract($context); ?>' . $code . '<?php return ob_get_clean();';
      
      $func = create_function('$context', $code);
      return $func((array) $context);
    });
    
    // Return function or call function depending on context
    return self::_wrap(((isset($this) && isset($this->_wrapped) && $this->_wrapped) || !is_null($context)) ? $return($context) : $return);
  }
public function template ( $ code = null , $ context = null ) { list ( $ code , $ context ) = self :: _wrapArgs ( func_get_args ( ) , 2 ) ; $ class_name = __CLASS__ ; $ return = self :: _wrap ( function ( $ context = null ) use ( $ code , $ class_name ) { $ ts = $ class_name :: getInstance ( ) -> _template_settings ; // Wrap escaped, interpolated, and evaluated blocks inside PHP tags extract ( ( array ) $ context ) ; preg_match_all ( $ ts [ 'escape' ] , $ code , $ vars , PREG_SET_ORDER ) ; if ( count ( $ vars ) > 0 ) { foreach ( $ vars as $ var ) { $ echo = $ class_name :: TEMPLATE_OPEN_TAG . ' echo htmlentities(' . trim ( $ var [ 1 ] ) . '); ' . $ class_name :: TEMPLATE_CLOSE_TAG ; $ code = str_replace ( $ var [ 0 ] , $ echo , $ code ) ; } } preg_match_all ( $ ts [ 'interpolate' ] , $ code , $ vars , PREG_SET_ORDER ) ; if ( count ( $ vars ) > 0 ) { foreach ( $ vars as $ var ) { $ echo = $ class_name :: TEMPLATE_OPEN_TAG . ' echo ' . trim ( $ var [ 1 ] ) . '; ' . $ class_name :: TEMPLATE_CLOSE_TAG ; $ code = str_replace ( $ var [ 0 ] , $ echo , $ code ) ; } } preg_match_all ( $ ts [ 'evaluate' ] , $ code , $ vars , PREG_SET_ORDER ) ; if ( count ( $ vars ) > 0 ) { foreach ( $ vars as $ var ) { $ echo = $ class_name :: TEMPLATE_OPEN_TAG . trim ( $ var [ 1 ] ) . $ class_name :: TEMPLATE_CLOSE_TAG ; $ code = str_replace ( $ var [ 0 ] , $ echo , $ code ) ; } } $ code = str_replace ( $ class_name :: TEMPLATE_OPEN_TAG , '<?php ' , $ code ) ; $ code = str_replace ( $ class_name :: TEMPLATE_CLOSE_TAG , '?>' , $ code ) ; // Use the output buffer to grab the return value $ code = 'ob_start(); extract($context); ?>' . $ code . '<?php return ob_get_clean();' ; $ func = create_function ( '$context' , $ code ) ; return $ func ( ( array ) $ context ) ; } ) ; // Return function or call function depending on context return self :: _wrap ( ( ( isset ( $ this ) && isset ( $ this -> _wrapped ) && $ this -> _wrapped ) || ! is_null ( $ context ) ) ? $ return ( $ context ) : $ return ) ; }
Compile templates into functions that can be evaluated for rendering
Compile templates into functions that can be evaluated for rendering