switcher control elementor
<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {
protected function _register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => __( 'Content', 'plugin-name' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'show_title',
[
'label' => __( 'Show Title', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'your-plugin' ),
'label_off' => __( 'Hide', 'your-plugin' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'title',
[
'label' => __( 'Title', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => __( 'Default title', 'plugin-domain' ),
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
if ( 'yes' === $settings['show_title'] ) {
echo '<h2>' . $settings['title'] . '</h2>';
}
}
protected function _content_template() {
?>
<# if ( 'yes' === settings.show_title ) { #>
<h2>{{{ settings.title }}}</h2>
<# } #>
<?php
}
}
Are there any code examples left?
New code examples in category Other