elementor repeater

Solutions on MaxInterview for elementor repeater by the best coders in the world

showing results for - "elementor repeater"
Louis
02 Apr 2017
1<?php
2
3class Elementor_Widget_Test extends \Elementor\Widget_Base {
4
5	public function get_name() {
6		return 'test';
7	}
8
9	public function get_title() {
10		return __( 'Test', 'elementor' );
11	}
12
13	protected function _register_controls() {
14
15		$this->start_controls_section(
16			'content_section',
17			[				'label' => __( 'Content', 'plugin-name' ),				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,			]
18		);
19
20		$repeater = new \Elementor\Repeater();
21
22		$repeater->add_control(
23			'list_title', [				'label' => __( 'Title', 'plugin-domain' ),				'type' => \Elementor\Controls_Manager::TEXT,				'default' => __( 'List Title' , 'plugin-domain' ),				'label_block' => true,			]
24		);
25
26		$repeater->add_control(
27			'list_content', [				'label' => __( 'Content', 'plugin-domain' ),				'type' => \Elementor\Controls_Manager::WYSIWYG,				'default' => __( 'List Content' , 'plugin-domain' ),				'show_label' => false,			]
28		);
29
30		$repeater->add_control(
31			'list_color',
32			[				'label' => __( 'Color', 'plugin-domain' ),				'type' => \Elementor\Controls_Manager::COLOR,				'selectors' => [					'{{WRAPPER}} {{CURRENT_ITEM}}' => 'color: {{VALUE}}'				],
33			]
34		);
35
36		$this->add_control(
37			'list',
38			[				'label' => __( 'Repeater List', 'plugin-domain' ),				'type' => \Elementor\Controls_Manager::REPEATER,				'fields' => $repeater->get_controls(),				'default' => [					[						'list_title' => __( 'Title #1', 'plugin-domain' ),						'list_content' => __( 'Item content. Click the edit button to change this text.', 'plugin-domain' ),					],
39					[						'list_title' => __( 'Title #2', 'plugin-domain' ),						'list_content' => __( 'Item content. Click the edit button to change this text.', 'plugin-domain' ),					],
40				],
41				'title_field' => '{{{ list_title }}}',
42			]
43		);
44
45		$this->end_controls_section();
46
47	}
48
49	protected function render() {
50		$settings = $this->get_settings_for_display();
51
52		if ( $settings['list'] ) {
53			echo '<dl>';
54			foreach (  $settings['list'] as $item ) {
55				echo '<dt class="elementor-repeater-item-' . $item['_id'] . '">' . $item['list_title'] . '</dt>';
56				echo '<dd>' . $item['list_content'] . '</dd>';
57			}
58			echo '</dl>';
59		}
60	}
61
62	protected function _content_template() {
63		?>
64		<# if ( settings.list.length ) { #>
65		<dl>
66			<# _.each( settings.list, function( item ) { #>
67				<dt class="elementor-repeater-item-{{ item._id }}">{{{ item.list_title }}}</dt>
68				<dd>{{{ item.list_content }}}</dd>
69			<# }); #>
70			</dl>
71		<# } #>
72		<?php
73	}
74}