• Resolved callender

    (@jimcallender)


    Hi there,

    I am creating a page template using CMB2 – I have a panel containing a wysiwig and text field. I want to have a repeater them both, not just a single field. How do I do this?

    Screenshot of what am I wanting to repeat – the entire panel, not just one block.

    https://www.evernote.com/l/AAFxSXJT_OhNyrlts45yAiMy8_LF6DKBwWM

    This is what I am currently using for a panel – with the custom fields inside this.

    $panel1_box = new_cmb2_box( array(
            'id'            => $prefix . 'panel_one',
            'title'         => __( 'Panel 1', 'cmb2' ),
            'object_types'  => array( 'page', ),
    				'show_on'      => array( 'id' => array( 274, ) ),
            'priority'      => 'high',
        ) );

    Thanks in advance,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What have you tried thus far in terms of the individual fields? What are you experiencing vs what are you expecting to experience?

    If you could provide all of the metabox code you have at the moment, that’d be a big help.

    Thread Starter callender

    (@jimcallender)

    Thanks for the reply Michael.

    Please find the code that I need to make repeatable – into a group.

    Thanks again, in advance!

    $panel9_box = new_cmb2_box( array(
    	'id'            => $prefix . 'panel9_box',
    	'title'         => __( 'Industry Table 5', 'cmb2' ),
    	'object_types'  => array( 'page', ),
    	'show_on'      => array( 'id' => array( 1741, ) ),
    	'priority'      => 'high',
    	'repeatable' => true,
    ));
    
    $panel9_box->add_field( array(
    		'name'    => __( 'Table Heading', 'cmb2' ),
    		'id'    => 'panel9_indheading',
    		'type'    => 'text',
    ));
    
    $panel9_box->add_field( array(
    		'name'    => __( 'Table Content', 'cmb2' ),
    		'id'      => 'panel9_indcontent',
    		'type'    => 'wysiwyg',
    ));
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Having some minor issues with regards to the wysiwyg field, but something like the following should get you pretty close:

    $panel9_box = new_cmb2_box( array(
    	'id'           => $prefix . 'panel9_box',
    	'title'        => __( 'Industry Table 5', 'cmb2' ),
    	'object_types' => array( 'page', ),
    	'priority'     => 'high',
    	'repeatable'   => true,
    ) );
    
    $group_field_id = $panel9_box->add_field( array(
    	'id'          => $prefix . 'demo',
    	'type'        => 'group',
    	'description' => esc_html__( 'Generates reusable form entries', 'cmb2' ),
    	'options'     => array(
    		'group_title'   => esc_html__( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number
    		'add_button'    => esc_html__( 'Add Another Entry', 'cmb2' ),
    		'remove_button' => esc_html__( 'Remove Entry', 'cmb2' ),
    		'sortable'      => true, // beta
    		// 'closed'     => true, // true to have the groups closed by default
    	),
    ) );
    
    $panel9_box->add_group_field( $group_field_id, array(
    	'name' => __( 'Table Heading', 'cmb2' ),
    	'id'   => 'panel9_indheading',
    	'type' => 'text',
    	// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
    ) );
    
    $panel9_box->add_group_field( $group_field_id, array(
    	'name' => __( 'Table Content', 'cmb2' ),
    	'id'   => 'panel9_indcontent',
    	'type' => 'wysiwyg',
    ) );
    

    In the extra instances, the WYSIWYG field isn’t working quite right, not sure why at the moment

    From the 2.2.3 release:
    Make wysiwyg editors work in the repeatable groups context. A standard repeatable (non-group) wysiwyg field is not supported (but will possibly be included in a future update). Props @johnsonpaul1014 (#26, #99, #260, #264, #356, #431, #462, #657, #693).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to create repeatable blocks (not custom fields)’ is closed to new replies.