Alternative implementation of templates in 1C-Bitrix
A typical situation. A parameter is set on the page that determines whether to display the page title or not. This cannot be done using standard Bitrix tools, since the title is shown before the page content. The way out of the situation is to use your template system. I developed it already a year and a half ago and successfully use it in all my projects. So, the system is as follows. We buffer the entire content of the page, attach the template, and paste the content into it as a variable. A practical implementation is as follows:
header.php file: footer.php file: template.php file:
<?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
ob_start();
?><?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
$WORK_AREA = ob_get_clean(); // Получаем контент рабочей области страницы
include_once("template.php");
?><?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<html>
<body>
<?=$WORK_AREA?>
</body>
</html>As a result, we have a complete website template in the template.php file. We solve two main problems voiced earlier. The only minus is that editing the template through the admin panel is no longer possible. Although this can also be considered a plus.