Skip to content

Commit 364a14c

Browse files
Update widget dependencies (#301)
1 parent 0cf754d commit 364a14c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/widgets/widget-dependencies.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,35 @@ class Elementor_Test_Widget_2 extends \Elementor\Widget_Base {
108108

109109
This way, Elementor can build the dependency tree and enqueue only dependencies for widgets used in the page.
110110

111+
### Using Elementor Assets
112+
113+
Third-party developers can use assets registered by Elementor, for instance using [Swiper](https://swiperjs.com/) to create carousel-based widgets.
114+
115+
```php
116+
class Elementor_Test_Widget extends \Elementor\Widget_Base {
117+
118+
public function get_style_depends(): array {
119+
return [ 'swiper', 'widget-custom-style' ];
120+
}
121+
122+
public function get_script_depends(): array {
123+
return [ 'swiper', 'widget-custom-script' ];
124+
}
125+
126+
}
127+
```
128+
129+
Elementor registers swiper for its carousel widgets, and Elementor Pro and many other Elementor Addons use it instead of registering its own versiosn of the library.
130+
111131
### Using Elementor Scripts
112132

113-
Widgets can also use scripts registered by Elementor:
133+
To use different Elementor JS methods, widgets needs to declare `elementor-frontend` as a dependency:
114134

115135
```php
116136
class Elementor_Test_Widget extends \Elementor\Widget_Base {
117137

118138
public function get_script_depends(): array {
119-
return [ 'elementor-frontend' ];
139+
return [ 'elementor-frontend', 'widget-custom-script' ];
120140
}
121141

122142
}

0 commit comments

Comments
 (0)