Elementor Extension:如何将转发器项目标题设置为 select 的当前值

Elementor Extension: How can i set a repeater item title to the current value of a select

我目前正在开发一个 elementor 扩展,但遇到以下问题:我想将转发器项目的标题设置为 select 的当前值。如果我的 select 控件标题为 'country' 并且我使用 {{{country}}} lateron,我只会得到 1,2,3,4,5

我在 elementor 文档中找不到任何关于此的信息


        require_once(plugin_dir_path(__FILE__).'countries.php');

        $this->start_controls_section(
            'content_section',
            [
                'label' => __( 'Content', 'plugin-name' ),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
            'country',
            [
                'label' => __('Country Name', 'elementor-cc-details'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '',
                'options' => $countries,
                'label_block' => true
            ]
        );


        $repeater->add_control(
            'list_content', [
                'label' => __( 'Content', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::WYSIWYG,
                'default' => __( 'List Content' , 'plugin-domain' ),
                'show_label' => false,
            ]
        );



        $this->add_control(
            'list',
            [
                'label' => __( 'Repeater List', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [

                ],
                'title_field' => '{{{ country}}}',
            ]
        );

        $this->end_controls_section();

    }

预期的结果是,如果我 select <select> 中的一个值,转发器项将其值作为名称。也许是 {{{ country.select }} } 之类的。我没发现。

我使用变通方法解决了我的问题。真正的问题还没有解决,因为你不能在键和值之间进行选择。

临时解决方案是像这样使用国家/地区数组

$countries = [
"Afghanistan" => "Afghanistan",
"Albania" => "Albania",
"Algeria" => "Algeria",
"Andorra" => "Andorra",
"Angola" => "Angola",
...

因为 {{{ country }}} 变量自动使用数组键(如果不存在 1,2,3,4,5)。