Include JQuery plugin into theme

To include jQuery plugin to a theme the following “magic trick” is required (here is an example for OwlCarousel):

<script>
  Liferay.Loader.define._amd = Liferay.Loader.define.amd;
  Liferay.Loader.define.amd = false;
</script>
<script type="text/javascript" src="${javascript_folder}/owl-carousel/owl.carousel.js"  />
<script>
  Liferay.Loader.define.amd = Liferay.Loader.define._amd;
</script>

(add this code in ‘head’ section of portal_normal.ftl file)
After this you can you your jQuery plugin in theme. For this example:


var $slider = $('#slider');
$slider.owlCarousel({
   items:1,
   loop:true,
   margin:10,
   autoplay:true,
   autoplayTimeout: 3000,
   autoplayHoverPause:true,
   pagination: true
});

Hope, this will help :)

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration