landing.repo.register
Scope: landing Permissions to execute: for all
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.
When developing a new block or updating an existing one you may need to view the resulting changes quicker than when re-adding or setting a RESET flag. It's recommended to use the method landing.block.updatecontent. This method passes an arbitrary content to the block and shows changes almost immediately. As soon as the development process is complete, creator can perform a final registration.
This method is suitable only for content updates. When updating the manifest, block must be re-registered (without re-adding it to the page).
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:
If a required category is not listed, just write it as text in the manifest and the category will be added. The value of Additional parameters:
| |
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()); } );