Documentation

Components inside block

Attention! We strongly recommend first to learn more about Sites module REST documentation to understand how the module functions (with REST available in Bitrix24 Self-hosted editions). View this documentation as useful source when working with Bitrix24 Self-hosted editions and find out more details about API and only REST is not enough.

Unavailable for REST!

Allocating a component (or multiple components) inside a block is quite easy. Create a call for the required components inside block.php.

<?php
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true)
{
   die();
}
?>
<section class="landing-block g-pt-100 g-pb-100">
   <div class="container g-font-size-13">
      <?$APPLICATION->IncludeComponent(
         "bitrix:catalog.element",
         "bootstrap_v4",
         array(
            "COUNT_DISCOUNT_4_ALL_QUANTITY" => "N",
            "DEFERRED_REFRESH" => 'N',
            "SHOW_FILTER" => 'N',
            "TOTAL_BLOCK_DISPLAY" => ['top', 'bottom'],
         ),
         false
      );?>
   </div>
</section>

Please note, block parameters are preset. Contrary on the simplest html-block, here, the system constant B_PROLOG_INCLUDED is checked in the first string to avoid directly accessing to file.

When you need to access specific block settings, block manifest node key must have necessary parameter codes specified the nodes key:

...
'nodes' => array(
   'bitrix:catalog.element' => array(
      'type' => 'component',
      'extra' => array(
         'editable' => array(
            'ELEMENT_ID' => array(),
            'HIDE_NOT_AVAILABLE' => array(),
            'DISCOUNT_PERCENT_POSITION' => array(
               'style' => true
            ),
         )
      )
   ),
),
...

When you are aware of block manifest contents, you will easily see that here bitrix:catalog.element acts as selector, but is the name of component placed inside the block. Array editable keys are the settings that we permit for updating by user within a specific block. Properties, marked as such will be available in the block edit form. In case when specified style = true, the setting will be included in block design edit form.

Parameter name, its type and other parameters are sourced directly from component parameter. This way, keys listed here are mandatory for component parameters (i. e. written in .parameters.php).


Component parameter editing inside blocks

Finally, block with a component is allocated on a page. How to modify a component calling parameter? Only parameters located in block manifest can be modified.

Here is the code that changes a parameter (array can be passed directly as well):

if (\Bitrix\Main\Loader::includeModule('landing'))
{
   \Bitrix\Landing\Landing::setEditMode(true);

   $landing = \Bitrix\Landing\Landing::createInstance(
      5597
   );
   if ($landing->exist())
   {
      foreach ($landing->getBlocks() as $block)
      {
         if ($block->getId() == 44131)
         {
            $block->updateNodes([
               'bitrix:catalog.section' => [
                  'MESS_BTN_BUY' => 'Add to my cart'
               ]
            ]);
            $block->save();
            $landing->getError()->copyError(
               $block->getError()
            );
         }
      }
   }


   foreach ($landing->getError()->getErrors() as $error)
   {
      echo $error->getCode() . ': ';
      echo $error->getMessage();
      echo "\n";
   }
}


© «Bitrix24», 2001-2024
Up