Can't get text field from settings to render inside a view

Support MB Settings Page Can't get text field from settings to render inside a viewResolved

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #37104
    ArnoArno
    Participant

    Hi,

    I have added a settings page, and a custom text field. I entered a text and it is saved.

    Now I want to display that text in a view. If I click the field in the view builder, it gives me this:

    <div>{% set group = attribute( site, 'site-configuration' ) %}
    {{ group.site_settings_texts_read_more }}</div>

    But it renders and empty <div>. What could cause this?

    #37109
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Can you please share the code that creates the settings page and custom fields on your site? I do not see any issue when showing a text value of a settings page with the view.

    #37113
    ArnoArno
    Participant

    How do I get that code? I created it through the UI with MB Settings Page.

    #37124
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please refer to this documentation to get the PHP code https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code

    #37126
    ArnoArno
    Participant

    Hi,

    Here's the field group:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Site settings - Texts', 'your-text-domain' ),
            'id'             => 'site-settings-texts',
            'settings_pages' => ['site-configuration'],
            'tab'            => 'tab3',
            'fields'         => [
                [
                    'name'              => __( 'Maps not available', 'your-text-domain' ),
                    'id'                => $prefix . 'site_settings_texts_maps_not_available',
                    'type'              => 'text',
                    'label_description' => __( 'Text to show when maps are not available at all', 'your-text-domain' ),
                ],
                [
                    'name'              => __( 'Maps for authenticated users only', 'your-text-domain' ),
                    'id'                => $prefix . 'site_settings_texts_maps_for_authenticated_users_only',
                    'type'              => 'text',
                    'label_description' => __( 'Text to show when maps are only available to authenticated users', 'your-text-domain' ),
                ],
                [
                    'name'              => __( 'Read more', 'your-text-domain' ),
                    'id'                => $prefix . 'site_settings_texts_read_more',
                    'type'              => 'text',
                    'label_description' => __( 'Button or link text to click to more details', 'your-text-domain' ),
                ],
                [
                    'name'              => __( 'Advanced filters', 'your-text-domain' ),
                    'id'                => $prefix . 'site_settings_texts_advanced_filters',
                    'type'              => 'text',
                    'label_description' => __( 'Label for "Advanced filters"', 'your-text-domain' ),
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    Here's the settings page:

    <?php
    add_filter( 'mb_settings_pages', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $settings_pages ) {
    	$settings_pages[] = [
            'menu_title' => __( 'Site configuration', 'your-text-domain' ),
            'id'         => 'site-configuration',
            'position'   => 80,
            'style'      => 'no-boxes',
            'columns'    => 1,
            'tabs'       => [
                'tab1' => 'General',
                'tab2' => 'Maps',
                'tab3' => 'Texts',
            ],
            'tab_style'  => 'left',
            'icon_url'   => 'dashicons-admin-generic',
        ];
    
    	return $settings_pages;
    }
    #37132
    ArnoArno
    Participant

    By the way, I was able to retrieve the values of a Text and Checkbox field from the Page Settings, through Kadence Blocks. So the fields basically works, it's just that the code inserted into the view via the Insert Field button does not work.

    #37150
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I do not see any issue when getting the field value from the settings page and showing it on the frontend. Here is the screen record https://monosnap.com/file/870jDUF3AMJBS7EujcbupTFZAXLwfy

    #37152
    ArnoArno
    Participant

    Thanks. I'm doing exactly what you did and nothing is rendered. How can I send you a login to my site?

    #37175
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please share your site credentials via this contact form https://metabox.io/contact/
    I will take a closer look.

    #37179
    ArnoArno
    Participant

    Thanks, I just filled out the form.

    #37245
    Long NguyenLong Nguyen
    Moderator

    This issue is resolved by adding the option name of the settings page in the builder to make it works.

    Let me know if you have any questions.

    #40287
    HeaveHeave
    Participant

    Sorry, solution is unclear.

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