Custom Functions To Access Complex Data Dynamically
-
Hello,
I am want to use carbon fields to create a custom function that checks to see if “enable full width” has been selected inside a complex field, if so add a class, if not add a class.
below is my function, complex field, and html:
if (!function_exists('enable_full_width_section')) { function enable_full_width_section(){ if (carbon_get_the_post_meta(get_the_ID(), 'enable_full_width_section')){ $class = 'container-fluid'; } else{ $class = 'container'; } echo $class; } }
Container::make( 'post_meta', 'Custom Data' ) ->show_on_post_type( 'page' ) ->add_fields( array( Field::make( 'complex', 'crb_layouts' ) ->add_fields( 'two_column_layout', array( Field::make('checkbox', 'enable_full_width_section')->set_option_value('yes'), Field::make( 'rich_text', 'column_left' )->set_width(50), Field::make( 'rich_text', 'column_right' )->set_width(50), ) ) ->add_fields( 'full_width_layout', array( Field::make('checkbox', 'full_width_section')->set_option_value('yes'), Field::make( 'rich_text', 'column' ), )), ) );
function zgm_two_column_layout($layout) { $column_left = $layout['column_left']; $column_right = $layout['column_right']; ?> <div class="section <?php enable_full_width_section(); ?>"> <div class="row"> <div class="col-sm-6"> <?php echo $column_left; ?> </div> <div class="col-sm-6"> <?php echo $column_right; ?> </div> </div> </div> <?php }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Functions To Access Complex Data Dynamically’ is closed to new replies.