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
- This topic has 11 replies, 3 voices, and was last updated 2 years, 3 months ago by
Heave.
-
AuthorPosts
-
July 21, 2022 at 8:49 PM #37104
Arno
ParticipantHi,
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?
July 21, 2022 at 11:00 PM #37109Long Nguyen
ModeratorHi,
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.
July 21, 2022 at 11:14 PM #37113Arno
ParticipantHow do I get that code? I created it through the UI with MB Settings Page.
July 22, 2022 at 12:57 PM #37124Long Nguyen
ModeratorHi,
Please refer to this documentation to get the PHP code https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code
July 22, 2022 at 3:10 PM #37126Arno
ParticipantHi,
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; }
July 22, 2022 at 9:32 PM #37132Arno
ParticipantBy 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.
July 23, 2022 at 9:59 PM #37150Long Nguyen
ModeratorHi,
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
July 23, 2022 at 10:44 PM #37152Arno
ParticipantThanks. I'm doing exactly what you did and nothing is rendered. How can I send you a login to my site?
July 25, 2022 at 12:09 PM #37175Long Nguyen
ModeratorHi,
Please share your site credentials via this contact form https://metabox.io/contact/
I will take a closer look.July 25, 2022 at 1:13 PM #37179Arno
ParticipantThanks, I just filled out the form.
July 28, 2022 at 11:03 AM #37245Long Nguyen
ModeratorThis 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.
January 23, 2023 at 4:45 PM #40287Heave
ParticipantSorry, solution is unclear.
-
AuthorPosts
- You must be logged in to reply to this topic.