Enclose group of fields in a div?

Support General Enclose group of fields in a div?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #42539
    maybeadevmaybeadev
    Participant

    Hi:

    Is there a way to wrap a group of fields inside of a custom div block?

    We tried using custom_html to set a 'div' at the top and bottom of the group of fields. But that doesn't work because metabox / browser seems to add a closing div automatically in the custom_html field.

    Thanks!

    #42540
    PeterPeter
    Moderator

    Hello,

    If you want to wrap a field in a custom HTML code, please use the field settings before and after. Read more in the documentation https://docs.metabox.io/field-settings/ (Advanced tab).

    #42543
    maybeadevmaybeadev
    Participant

    Hi:

    Thanks for the response. However, I'm asking about using PHP code to do this, not using the UI or AIO.

    I thought about trying to sue the rwmb_being_html or rwmb_wrapper_html filters but those seem to only apply to a full group instead of a subset of fields within the group.

    Thanks.

    #42548
    PeterPeter
    Moderator

    Hello,

    You can use those filters to wrap the subfield in a custom HTML, for example:

    add_filter( 'rwmb_subfieldID_wrapper_html', function( $html, $field, $meta ) {
        $html = '<div class="my-class">'. $html . '</div>';
        return $html;
    }, 10, 3);
    #42558
    maybeadevmaybeadev
    Participant

    Hi:

    I think something got lost in translation.

    I'm looking to wrap a SUBSET of fields with a custom div. So, something like this.

    // CUSTOM HTML
    array(
        'type' => 'custom_html',
        'std' => __( '<div class="myclass">', 'my-metaboxes' ),
        'id'   => 'myid',
    ),
    
    /* Some fields here... */
    
    // CUSTOM HTML
    array(
        'type' => 'custom_html',
        'std' => __( '</div>', 'my-metaboxes' ),
        'id'   => 'myid2', 
    ),

    You'll notice that the fields specifed by 'some fields here' are being wrapped in a custom div.
    That's the effect I've trying to achieve.

    I don't think the suggested use of the rwmb_subfieldID_wrapper_html filter will allow for this?

    Thanks!

    #42594
    PeterPeter
    Moderator

    Hello,

    Yes, using the filter rwmb_subfieldID_wrapper_html or custom_html field, you need to add the close tags for all open tags. Only the field settings before and after can support your case.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.