Views: 700 (Data available since 06.02.2017)
Last Modified: 14.07.2014
Simple examples of template application depending on various conditions
phone section property is equal to Y
If the current section is equal to
If a current user is the administrator
If the template must be linked to a dynamic page (in the example, to a detailed page (card) of the goods)
Connection of Favicon.ico for Various Templates
In order to have different symbols in different site templates a call of a symbol from the template must be added to header.php of the template:
<link rel="icon" type="image/x-icon"
Separate Template for the Home Page of the Site
In addition to the main template for all site pages, a required template must be connected through the condition For folder or file indicating
/index.php and taking into account the application sorting index of the template.
Change of the Site Template Depending on the Time Parameter
Task: How to implement a site template change depending on the time parameter (two templates in total, but they must be changed every hour)?
For this, the current template must be changed according to the condition PHP expression.
On odd hours:
((date("H")+6)%2) == 1
On even hours:
((date("H")+6)%2) == 0
+6 indicates the time zone.
Application of the Template Using Both Conditions Simultaneously
Task: How to set a template according to 2 conditions simultaneously (for a group of users and for both folder and file)?
For this, the current template must be changed according to the condition PHP expression:
in_array($groupID, $USER->GetUserGroupArray()) || strpos($APPLICATION->GetCurDir(), "/dir/")!==false || $APPLICATION->GetCurPage()=="/dir/file.php"
Template Application Only to the Files with a Specific Extension
Task: Which PHP expression should be used so that the template applies to all pages ended in .php but not .html?
Solution: change of the template according to the condition PHP expression:
substr($APPLICATION->GetCurPage(true), -4) == ".php"
Similarly for the files with the html extension:
substr($APPLICATION->GetCurPage(true), -5) == ".html"
Change of Site Header Design for Different Sections
Task: The site is divided into several sections. The idea is that each section must have its own header in the design. There are no other changes in the design.
The component Insert include area is connected to the template:
<?$APPLICATION->IncludeComponent("bitrix:main.include", ".default", array(
"AREA_FILE_SHOW" => "sect",
"AREA_FILE_SUFFIX" => "headerinc",
"AREA_FILE_RECURSIVE" => "Y",
"EDIT_TEMPLATE" => "sect_headerinc.php"
The header code of each section will be stored in the file sect_headerinc.php. The parameter
"AREA_FILE_RECURSIVE" => "Y" means that the same header will appear in all subsections of this section, unless the parental sect_headerinc.php is specifically shut off in any underlying sections.