true<\/code>. <\/p>\n\n\n\nThis is required so Bricks knows to render this custom element using the nestable render function in the builder, and to enable drag & drop inside the builder for this custom element.<\/p>\n\n\n\n
Nestable Element Template<\/h3>\n\n\n\n
You can define the structure of your custom element via the get_nestable_children<\/code> function. It expects to return an array of element definitions. <\/p>\n\n\n\nThis is best illustrated by having a look at the Nestable Slider elements’ get_nestable_children<\/code> function:<\/p>\n\n\n\npublic function get_nestable_children() {\n return [\n [\n 'name' => 'block',\n 'label' => esc_html__( 'Slide', 'bricks' ) . ' {item_index}',\n 'settings' => [\n '_hidden' => [\n '_cssClasses' => 'hidden-class', \/\/ CSS class not visible in builder UI\n ],\n ],\n 'children' => [\n [\n 'name' => 'heading',\n 'settings' => [\n 'text' => esc_html__( 'Slide', 'bricks' ) . ' {item_index}',\n ],\n ],\n [\n 'name' => 'button',\n 'settings' => [\n 'text' => esc_html__( 'I am a button', 'bricks' ),\n 'size' => 'lg',\n 'style' => 'primary',\n ],\n ],\n ],\n ],\n ];\n}<\/code><\/pre>\n\n\n\nThe code above adds a “Slide” block inside the nestable slider, which then contains a “Heading” & “Button” element. <\/p>\n\n\n\n
The children<\/code> property, if set, accepts an array of further nested elements. Specify the settings<\/code> array to populate individual elements inside your nestable element as needed.<\/p>\n\n\n\nNestable Render Function (PHP)<\/h3>\n\n\n\n
The only new function you need to add to your PHP render()<\/code> function is called render_children<\/code> and it requires the element instance $this<\/code> to be passed as the first parameter:<\/p>\n\n\n\npublic function render() {\n $output = \"<div {$this->render_attributes( '_root' )}>\";\n\n \/\/ Render children elements (= individual items)\n $output .= Frontend::render_children( $this );\n\n $output .= '<\/div>';\n\n echo $output;\n}<\/code><\/pre>\n\n\n\nNestable Render Function (Vue x-template)<\/h3>\n\n\n\n
To render elements inside your nestable element in your custom x-template, simply add the <bricks-element-children><\/code> component plus element<\/code> props as shown in the following code snippet:<\/p>\n\n\n\npublic function render_builder() {\n <script type=\"text\/x-template\" id=\"tmpl-bricks-element-custom-nestable\">\n <component :is=\"tag\">\n <h2>Title before nestable children<\/h2>\n <bricks-element-children :element=\"element\"\/>\n <p>Text node after nestable children<\/p>\n <\/component>\n <\/script>\n}<\/code><\/pre>\n\n\n\nNestable Element Items (in panel)<\/h3>\n\n\n\n
If your nestable element structure is based on items on the same level (such as our Accordion above), then you can add a Repeater (see builder panel in screenshot above) by adding a repeater<\/code> control with the items<\/code> property set to children<\/code>:<\/p>\n\n\n\npublic function set_controls() {\n \/\/ Array of nestable element.children (@since 1.5)\n $this->controls['_children'] = [\n 'type' => 'repeater',\n 'titleProperty' => 'label',\n 'items' => 'children',\n ];\n];<\/code><\/pre>\n\n\n\nIf you are start using and\/or experimenting with the new Nestable Elements API for your custom elements, we’d love to hear your feedback<\/a>. Does this API miss any features, did you encounter any bugs?<\/p>\n","protected":false},"excerpt":{"rendered":"Bricks 1.5 introduces Nestable Elements. Plus an API that allows you to programmatically define your own custom elements that can contain other elements. In exactly the structure you want. Prior to Bricks 1.5 every element in Bricks was “flat”. Meaning even though an element contained a deep HTML structure (like the Slider, etc.) you couldn’t […]<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":82,"template":"","format":"standard","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2644"}],"collection":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article"}],"about":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/types\/bricks_article"}],"author":[{"embeddable":true,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/users\/1"}],"version-history":[{"count":52,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2644\/revisions"}],"predecessor-version":[{"id":5129,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2644\/revisions\/5129"}],"wp:attachment":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/media?parent=2644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}