Skip to content

Commit

Permalink
Update widget dependencies (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-elementor authored Dec 23, 2024
1 parent 0cf754d commit 364a14c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/widgets/widget-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
}

}
Expand Down

0 comments on commit 364a14c

Please sign in to comment.