Nested Complex Fields PHP output sample code?
-
Hi,
I’m getting used to setting up complex fields for the backend. But I’m struggling when it comes to writing the php code for nested complex fields to show it’s output as html on a page. A bit of sample code would be of great help!
Currently I’ve created the following fields:
use Carbon_Fields\Container\Container; use Carbon_Fields\Field\Field; use Carbon_Fields\Field\Complex_Field; $section_labels = array('plural_name' => 'Sections', 'singular_name' => 'Section',); $row_labels = array('plural_name' => 'Rows', 'singular_name' => 'Row',); $column_labels = array('plural_name' => 'Columns', 'singular_name' => 'Column',); Container::make('post_meta', 'Page Builder') ->show_on_post_type('page') ->add_fields(array( Field::make('complex', 'lk_section', "") ->setup_labels($section_labels) ->add_fields(array( Field::make('complex', 'lk_row', "") ->setup_labels($row_labels) ->add_fields(array( Field::make('complex', 'lk_column', "") ->setup_labels($column_labels) ->add_fields(array( // Add complex fields for several types of content-blocks here Field::make("separator", "column_attributes", "Column Attributes"), Field::make('text', 'id', "ID")->set_width(15), Field::make('text', 'class', "Class")->set_width(15), Field::make('text', 'custom')->set_width(33), )), Field::make("separator", "row_attributes", "Row Attributes"), Field::make('text', 'id', "ID")->set_width(15), Field::make('text', 'class', "Class")->set_width(15), Field::make('text', 'custom')->set_width(33), Field::make("separator", "row_styling", "Row Styling"), )), Field::make("separator", "section_attributes", "Section Attributes"), Field::make('text', 'id', "ID")->set_width(15), Field::make('text', 'class', "Class")->set_width(15), Field::make('text', 'custom')->set_width(33), Field::make("separator", "section_styling", "Section Styling"), )), ));And would like to output it for example, as html like this:
<section class="custom-section-class"> <div class="custom-row-class"> <div class="custom-column-class"> </div> </div> </section>How would I go about it? For simplicity reasons ignore the other fields (id, custom).
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Nested Complex Fields PHP output sample code?’ is closed to new replies.