Title: Nested Complex Fields PHP output sample code?
Last modified: August 31, 2016

---

# Nested Complex Fields PHP output sample code?

 *  Resolved [Taiko Media](https://wordpress.org/support/users/taiko-media/)
 * (@taiko-media)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/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).
 * [https://wordpress.org/plugins/carbon-fields/](https://wordpress.org/plugins/carbon-fields/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * (@htmlburger)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097173)
 * Hey there,
 * We’ve prepared a quick example on how to output the sections, rows and columns
   based on the markup that you provided, considering the nested complex fields 
   that you’ve registered above.
 * You can find it here: [https://gist.github.com/tyxla/7c9c7691e6101375ea07](https://gist.github.com/tyxla/7c9c7691e6101375ea07)
 * Feel free to experiment with it.
 * Cheers
 *  Thread Starter [Taiko Media](https://wordpress.org/support/users/taiko-media/)
 * (@taiko-media)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097190)
 * Thanks! Your example code works perfect. I see where I went wrong in my attempts.
 * Your support is superb. I can’t contribute a lot in return, but if you ever need
   CF translated to Dutch, let me know!
 * Best,
    Richard
 *  Plugin Author [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * (@htmlburger)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097229)
 * Hey Richard,
 * Glad we were able to help.
 * We currently don’t have Dutch translation, so it would be really wonderful if
   you can contribute with it.
 *  Thread Starter [Taiko Media](https://wordpress.org/support/users/taiko-media/)
 * (@taiko-media)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097232)
 * I’ve added Carbon Fields along with the Dutch translation as a project on poeditor.
   com > [https://poeditor.com/join/project/TrICAM5zyU](https://poeditor.com/join/project/TrICAM5zyU)
 *  Plugin Author [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * (@htmlburger)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097254)
 * Hi Richard,
 * Thanks for the translation! We really appreciate it.
 * We’re developing the plugin in GitHub (and store the translations there as well).
   Do you want to add your translation file there? In case you do, you should follow
   the steps that we’ve outlined in the following GitHub issue [https://github.com/htmlburger/carbon-fields/issues/2](https://github.com/htmlburger/carbon-fields/issues/2)
 * Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Nested Complex Fields PHP output sample code?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/carbon-fields_cacbcc.svg)
 * [Carbon Fields](https://wordpress.org/plugins/carbon-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/carbon-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/carbon-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/carbon-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/carbon-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/carbon-fields/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [htmlBurger](https://wordpress.org/support/users/htmlburger/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/nested-complex-fields-php-output-sample-code/#post-7097254)
 * Status: resolved