td_api_block::add

Available on: Newspaper V11+

This api call is used to add new blocks to the theme. The block id must start with td_block_, that’s how the theme knows to only load the block when needed, basically if the block is not used on the current page, the files associated with it are not even loading. This ensure that the theme works as fast as possible and that high number of blocks do not affect performance.

Usage:

<?php td_api_block::add( $id, $params_array ) ?>

Parameters:

$id (integer) (required)

  • the block id – has to be different from the id’s used on the blocks which are already registered in the theme
  • important: the $id has to be formatted like this: td_flex_block_{your_unique_id}
    • example of valid $id’s: td_flex_block_custom, td_block_random_name etc

$params_array (array) (required)

  • an array which contains the parameters of the block (map_in_visual_composer, name, base, class, controls, category, icon, file, params)
Key name
Type
Description
map_in_td_composer boolean enable/disable the block appearance in tagDiv Composer
name string the block title, it appears in tagDiv Composer
base string shortcode tag. For [my_shortcode] shortcode base is my_shortcode
class string CSS class which will be added to the shortcode’s content element in the page edit screen in tagDiv Composer edit mode
controls string Default: “full”
category string category which best suites to describe functionality of this shortcode. Default category: Blocks. You can add your own category, simply enter new category title here
tdc_category string Blocks(tagDiv composer) …
icon string URL or CSS class with icon image, the icon is displayed in Visual Composer
file string the path for the block template file
params array the array of parameters received from the block settings panel

Examples:

In the following example we’ll add Flex Block Custom , you can see how the code looks on plugin, you have to modify the file path to match with the plugin current folder, we use the variables which were introduced in the Plugin Method section:

           // Add a new block
            td_api_block::add( 'td_flex_block_custom',
                array(
                    'map_in_visual_composer' => false,
                    'map_in_td_composer'     => true,
                    "name"                   => 'Custom Flex Block',
                    "base"                   => 'td_flex_block_custom',
                    "class"                  => 'td_flex_block_custom',
                    "controls"               => "full",
                    "category"               => 'Blocks',
                    'tdc_category'           => 'Blocks',
                    'icon'                   => 'icon-pagebuilder-td_flex_block_custom',
                    'file'                   => $this->plugin_path . '/shortcodes/td_flex_block_custom.php',

                    "params"                 =>
                        array_merge(
                            td_config::get_map_block_general_array(),
                            array(
                                array(
                                    "param_name"  => "mc_tl",
                                    "type"        => "textfield",
                                    "value"       => '',
                                    "heading"     => 'Title length',
                                    "description" => "",
                                    "holder"      => "div",
                                    "class"       => "tdc-textfield-small",
                                    "placeholder" => '25',
                                    "info_img" => "https://cloud.tagdiv.com/help/title_length.png",
                                ),
                            ),
                            td_config::get_map_filter_array(),
                            array(
                                array(
                                    "param_name"  => "modules_height",
                                    "type"        => "textfield-responsive",
                                    "value"       => '',
                                    "heading"     => 'Modules height',
                                    "description" => "",
                                    "holder"      => "div",
                                    "class"       => "tdc-textfield-small",
                                    "placeholder" => "460",
                                    "group"       => "Layout",
                                ),
                                array(
                                    "param_name"  => "image_size",
                                    "type"        => "dropdown",
                                    "value"       => array(
                                        'Small - 696px'  => '',
                                        'Large - 1068px' => 'td_1068x0',
                                        'Full - 1920px'  => 'td_1920x0'
                                    ),
                                    "heading"     => 'Image size',
                                    "description" => "",
                                    "holder"      => "div",
                                    "class"       => "tdc-dropdown-big",
                                    "group"       => "Layout",
                                    "info_img" => "https://cloud.tagdiv.com/help/module_image_size.png",
                                ),
                            ),
                            td_config::get_map_block_ajax_filter_array(),
                            td_config::get_map_block_pagination_array()

                        )
                )
            );