From 364a14cba0b095c2842d257304f0f2248936c018 Mon Sep 17 00:00:00 2001 From: Rami Yushuvaev <92088692+rami-elementor@users.noreply.github.com> Date: Sun, 22 Dec 2024 23:59:20 -0800 Subject: [PATCH] Update widget dependencies (#301) --- src/widgets/widget-dependencies.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/widgets/widget-dependencies.md b/src/widgets/widget-dependencies.md index e1c033e..f09b79a 100644 --- a/src/widgets/widget-dependencies.md +++ b/src/widgets/widget-dependencies.md @@ -108,15 +108,35 @@ class Elementor_Test_Widget_2 extends \Elementor\Widget_Base { This way, Elementor can build the dependency tree and enqueue only dependencies for widgets used in the page. +### Using Elementor Assets + +Third-party developers can use assets registered by Elementor, for instance using [Swiper](https://swiperjs.com/) to create carousel-based widgets. + +```php +class Elementor_Test_Widget extends \Elementor\Widget_Base { + + public function get_style_depends(): array { + return [ 'swiper', 'widget-custom-style' ]; + } + + public function get_script_depends(): array { + return [ 'swiper', 'widget-custom-script' ]; + } + +} +``` + +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. + ### Using Elementor Scripts -Widgets can also use scripts registered by Elementor: +To use different Elementor JS methods, widgets needs to declare `elementor-frontend` as a dependency: ```php class Elementor_Test_Widget extends \Elementor\Widget_Base { public function get_script_depends(): array { - return [ 'elementor-frontend' ]; + return [ 'elementor-frontend', 'widget-custom-script' ]; } }