,
,

/bitrix/php_interface/init.php :

1. $arCustomTemplateEngines, , :
   "_" => array(
      "templateExt" => array("1"[, "2"...]),
      "function" => "___"
   )

:
"_" - ;
"N" - , ;
"___" - , , .

2. :
     function ___($templateFile, $arResult, $arParams, $arLangMessages, $templateFolder, $parentTemplateFolder, $template),
:
     $templateFile – ,
     $arResult –
,
     $arParams – ,
     $arLangMessages – () ,
     $templateFolder – (
, ),
     $parentTemplateFolder -
, (
, ),
     $template – .

.

Smarty:

$arCustomTemplateEngines Smarty:

global $arCustomTemplateEngines;
$
arCustomTemplateEngines = array(
   "smarty" => array(
      "templateExt" => array("tpl"),
      "function" => "SmartyEngine"
   ),
);

SmartyEngine Smarty (. Smarty). Smarty , , .., Smarty:

function SmartyEngine($templateFile, $arResult, $arParams, $arLangMessages, $templateFolder, $parentTemplateFolder, $template)
{
   if (!defined("SMARTY_DIR"))
      define("SMARTY_DIR", "<
Smarty>/libs/");

   require_once( '<
Smarty>/libs/Smarty.class.php' );

   $smarty = new Smarty;

   $smarty->compile_dir = "<
Smarty>/templates_c/";
   $smarty->config_dir = "<
Smarty>/configs/";
   $smarty->template_dir = "<
Smarty>/templates/";
   $smarty->cache_dir = "<
Smarty>/cache/";

   $smarty->compile_check = true;
   $smarty->debugging = false;

   $smarty->assign("arResult", $arResult);
   $smarty->assign("arParams", $arParams);
   $smarty->assign("MESS", $arLangMessages);
   $smarty->assign("templateFolder", $templateFolder);
   $smarty->assign("parentTemplateFolder", $parentTemplateFolder);

   $smarty->display( $_SERVER["DOCUMENT_ROOT"].$templateFile );
}

"< Smarty>" Smarty.


XML/XSLT:

:

global $arCustomTemplateEngines;
$arCustomTemplateEngines = array(
   "xslt" => array(
      "templateExt" => array("xsl"),
      "function" => "XSLTEngine"
   ),
);

:

function CreateXMLFromArray($xDoc, $xNode, $ar)
{
   foreach($ar as $key=>$val)
   {
      if(!is_string($key) || strlen($key)<=0)
         $key = "value";

      $xElement = $xDoc->createElement($key);
      if(is_array($val))
      {
         CreateXMLFromArray($xDoc, $xElement, $val);
      }
      else
      {
         $xElement->appendChild($xDoc->createTextNode(iconv( SITE_CHARSET, "utf-8", $val)));
      }
      $xNode->appendChild($xElement);
   }
   return $xNode;
}

:

function XSLTEngine($templateFile, $arResult, $arParams, $arLangMessages, $templateFolder, $parentTemplateFolder, $template)
{
   $arResult["PARAMS"] = array(
      "templateFolder" => $templateFolder,
      "parentTemplateFolder" => $parentTemplateFolder,
      "arParams" => $arParams,
      "arLangMessages" => $arLangMessages
   );

   $xDoc = new DOMDocument("1.0", SITE_CHARSET);
   $xRoot = $xDoc->createElement('result');
   CreateXMLFromArray($xDoc, $xRoot, $arResult);
   $xDoc->appendChild($xRoot);

   $xXsl = new DOMDocument();
   $xXsl->load( $_SERVER["DOCUMENT_ROOT"].$templateFile );

   $xProc = new XSLTProcessor;
   $xProc->importStyleSheet($xXsl);

   echo $xProc->transformToXML($xDoc);
}