PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev3
Elementor Website Builder – more than just a page builder v3.28.0-dev3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / atomic-widgets / elements / has-template.php

has-template.php in Elementor Website Builder – more than just a page builder 3.28.0-dev3, at modules/atomic-widgets/elements/has-template.php

63 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Elements;
4
5 use Elementor\Modules\AtomicWidgets\TemplateRenderer\Template_Renderer;
6 use Elementor\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * @mixin Has_Atomic_Base
14 */
15 trait Has_Template {
16 protected function render() {
17 try {
18 $renderer = Template_Renderer::instance();
19
20 foreach ( $this->get_templates() as $name => $path ) {
21 if ( $renderer->is_registered( $name ) ) {
22 continue;
23 }
24
25 $renderer->register( $name, $path );
26 }
27
28 $context = [
29 'id' => $this->get_id(),
30 'type' => $this->get_name(),
31 'settings' => $this->get_atomic_settings(),
32 'base_styles' => $this->get_base_styles_dictionary(),
33 ];
34
35 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
36 echo $renderer->render( $this->get_main_template(), $context );
37 } catch ( \Exception $e ) {
38 if ( Utils::is_elementor_debug() ) {
39 throw $e;
40 }
41 }
42 }
43
44 protected function get_main_template() {
45 $templates = $this->get_templates();
46
47 if ( count( $templates ) > 1 ) {
48 Utils::safe_throw( 'When having more than one template, you should override this method to return the main template.' );
49
50 return null;
51 }
52
53 foreach ( $templates as $key => $path ) {
54 // Returns first key in the array.
55 return $key;
56 }
57
58 return null;
59 }
60
61 abstract protected function get_templates(): array;
62 }
63