How to create your own component?

The standard components shipped with the product enable developers to build any complex solution. To modify the behaviour of standard components, it is sufficient to alter the component template or reprocess parameters of a component in result_modifier.php.

result_modifier.php is included immediately before the component template. This script accepts an array of component results and an array of component parameters on input. This allows to alter the array of component results for a required template.

For example: a standard component fully satisfies requirements except that it does not return some required field. In this case, create a file result_modifier.php in the component template and add the field to the array of component results. Or, you can use this file for any other purpose.

However, developers may want to create custom, task-specific components.

Custom components can be created from scratch using the supplied documentation, or they can be based on standard components by changing their functions.

All components reside in /bitrix/components/. Standard components can be found in /bitrix/components/bitrix/. The contents of this folder is modified by the update system and must not be changed by developers.

Attention! Changing any file or structure of /bitrix/components/bitrix/ may cause unpredictable results.

Custom components can be saved in any subfolder of /bitrix/components/. For example, this demo site uses a folder /bitrix/components/demo/ to store examples of custom components.

In the demo site, you will find the following custom components:

  • The list of news component
  • News details component
  • The composite component: news

In this section, you will find examples of using these components.

You can add components in the visual editor:

My components

The following code is used to connect a component:

<?$APPLICATION->IncludeComponent("demo:news.detail", ".default", Array(
   "IBLOCK_TYPE" => "news",
   "IBLOCK_ID" => "3",
   "ELEMENT_ID" => $_REQUEST["ID"],
   "IBLOCK_URL" => "news_list.php",
   "CACHE_TYPE" => "A",
   "CACHE_TIME" => "3600",
   "DISPLAY_PANEL" => "N",
   "SET_TITLE" => "Y",
   "ADD_SECTIONS_CHAIN" => "N",
   "DISPLAY_DATE" => "Y",
   "DISPLAY_NAME" => "N",
   "DISPLAY_PICTURE" => "Y"
 )
);?>

Please note that the name of a subfolder of /bitrix/components/ is used to address components. For example, system components are connected using the following call:

$APPLICATION->IncludeComponent("bitrix:news.line", ...)

Custom components from /bitrix/components/demo are connected as follows:

$APPLICATION->IncludeComponent("demo:news.line", ...)

Note that modifying a standard component to create a custom one has a serious drawback: the component will not be updated, errors fixes and new features will not be available.