Documentation

landing.repo.register

landing.repo.register(code, fields, manifest)

This method adds block to a repository. Returns as error or as ID of added block. This ID is used to add a block to created landing pages.

Verification is performed when a block is added. If the block with this code is already present in the system, it will be deleted.

The method can return an error describing bad block content. In this case, first check the registered content by the method landing.repo.checkContent.

Parameters

Method Description Available from version
code Unique code of your block. It will be used to delete the block, if required.
fields Array of fields, describing your block. It consists of the following keys:
  • NAME - name of the block
  • DESCRIPTION - description of the block
  • SECTIONS - categories, in which the block shall appear, separated by comma (list to a category list)
  • If a required category is not listed, just write it as text in the manifest and the category will be added. The value of md5(strtolower($sectionName)) becomes the new category key.

  • PREVIEW - URL of the image, block preview
  • CONTENT - block html-contents
  • ACTIVE - block activity status (Y / N)
  • SITE_TEMPLATE_ID – binding of block to specific main module site template. For On-Premise versions only!

Additional parameters:

  • RESET - when 'Y' is passed, the system automatically updates layout for all blocks added to the page. Please, be advised, this technology is still in testing phase and requires separate testing on blocks that you would like to modify.
manifest Array of the manifest, used to describe the block.

Style attribute can be removed by the in-built sanitizer. To avoid it, use the bxstyle attribute instead. When added, the system will convert it into the standard style attribute.

Example

<?
//for illustration purposes, let's pass PHP-array for JS-library execution
$data = array(
   'code' => 'myblockx',
   'fields' => array(
      'NAME' => 'Test block',
      'DESCRIPTION' => 'Just try!',
      'SECTIONS' => 'cover,about',
      'PREVIEW' => 'https://www.bitrix24.com/images/b24_screen.png',
      'CONTENT' => '
<section class="landing-block">
   <div class="text-center g-color-gray-dark-v3 g-pa-10">
      <div class="g-width-600 mx-auto">
         <div class="landing-block-node-text g-font-size-12 ">
            <p>© 2017 All right reserved. Developed by
            <a href="#" class="landing-block-node-link g-color-primary">Bitrix24</a></p>
         </div>
      </div>
   </div>
</section>'
   ),
   'manifest' => array(
      'assets' => array(
         'css' => array(
            'https://site.com/aaa.css'
         ),
         'js' => array(
            'https://site.com/aaa.js'
         )
      ),
      'nodes' =>
         array(
            '.landing-block-node-text' =>
               array(
                  'name' => 'Text',
                  'type' => 'text',
               ),
            '.landing-block-node-link' =>
               array(
                  'name' => 'Link',
                  'type' => 'link',
               ),
         ),
      'style' =>
         array(
            '.landing-block-node-text' =>
               array(
                  'name' => 'Text',
                  'type' => 'typo',
               ),
            '.landing-block-node-link' =>
               array(
                  'name' => 'Link',
                  'type' => 'typo',
               ),
         ),
      'attrs' =>
         array(
           '.landing-block-node-text' =>
              array(
                 'name' => 'Copyright settings',
                 'attribute' => 'data-copy',
                 'items' => array(
                    'val1' => 'Value 1',
                    'val2' => 'Value 2'
                     )
                ),
         ),
   ),
);
?>
// Attention JS code follows below.
BX24.callMethod(
   'landing.repo.register',
   //abstract method, converting PHP-array into JS-object
   <?= \CUtil::PhpToJSObject($data)?>,
   function(result)
   {
      if(result.error())
         console.error(result.error());
      else
         console.info(result.data());
   }
);


© «Bitrix24», 2001-2024
Up