1

does any body have idea that how to include masonry in magento 2? as i added requirejs-config.js them in masonry i used require on the top of the code then i added this code in bottom of list.phtml

<script type="text/javascript">
        requirejs( [ 'require', 'jquery', 'masonry' ],
            function( require, $, Masonry ) {
// require jquery-bridget, it's included in masonry.pkgd.js
                require( [ 'jquery-bridget/jquery-bridget' ],
                    function( jQueryBridget ) {
                        // make Masonry a jQuery plugin
                        jQueryBridget( 'masonry', Masonry, $ );
                        // now you can use $().masonry()
                        $('.grid').masonry({
                            // your settings
                        });
                    }
                );
            });
    </script>

but i am getting this error continuously.

https://imgur.com/a/Bvu6jTA

0

$ seems undefined it means jquery not added in deps.

Change the code like below:

require(['jquery', 'masonry', 'jquery-bridget/jquery-bridget'],
    function( $, Masonry, jQueryBridget ) {
        // make Masonry a jQuery plugin
        jQueryBridget( 'masonry', Masonry, $ );
        // now you can use $().masonry()
        $('.grid').masonry({
            // your settings
        });
    }
);

I hope it will helps.

  • i think i have added the jquery in above code? – i_ali55 Mar 18 at 13:22
  • yeah but its seems undefined in require jquery-bridget – Sathish Mar 18 at 13:28
  • what is bridget? could you please specify your answer in detail? and where i use the above code? – i_ali55 Mar 18 at 13:34
  • after adding above code, prntscr.com/mzhts1 – i_ali55 Mar 18 at 13:38
  • in above screenshot error shows on custom.js? can you share your custom js? – Sathish Mar 18 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.