Elementor 开发者文档

title: "文本控件" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Editor Controls - Src - Repos


文本控件

Text Control

Elementor 文本控件显示一个简单的文本输入框。

该控件在继承 Base_Data_Control 类的 Control_Text 类中定义。

Text Control - block view

使用此控件时,应将 type 设置为 \Elementor\Controls_Manager::TEXT 常量。

参数

名称 类型 默认值 描述
type string text 控件的类型。
label string 显示在字段上方的标签。
description string 显示在字段下方的描述。
show_label bool true 是否显示标签。
label_block bool false 是否在单独一行显示标签。
separator string default 设置控件分隔符的位置。可用值为 defaultbeforeafterdefault 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 会将分隔符定位在控件之前/之后。
input_type string text 输入字段类型。可用值为所有 HTML5 支持的类型。
placeholder string 当字段没有值时显示的占位符。
title string 鼠标悬停时显示的字段标题。
classes string 在面板中向控件包装器添加自定义类。
default string 字段的默认值。

Return Value

(string) The text field value.

Usage

```php {14-22,35-37,48-50}

start_controls_section( 'content_section', [ 'label' => esc_html__( 'Content', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'widget_title', [ 'label' => esc_html__( 'Title', 'textdomain' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => esc_html__( 'Default title', 'textdomain' ), 'placeholder' => esc_html__( 'Type your title here', 'textdomain' ), ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); if ( empty( $settings['widget_title'] ) ) { return; } ?>
    <h2 class="title">
        <?php echo $settings['widget_title']; ?>
    </h2>
    <?php
}

protected function content_template(): void {
    ?>
    <#
    if ( '' === settings.widget_title ) {
        return;
    }
    #>
    <h2 class="title">
        {{{ settings.widget_title }}}
    </h2>
    <?php
}

} ```