Skip to main content

Include jquery, owl carousel, bootstrapjs in magento 2

 app/design/frontend/Vendor/Theme/Magento_Theme/layout/default.xml

 

 <referenceContainer name="after.body.start">
        <block class="Magento\Framework\View\Element\Template" name="custom.js" template="Magento_Theme::custom_js.phtml"/>
  </referenceContainer>
 

app/design/frontend/Vendor/Theme/requirejs-config.js

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

var config = {
    map: {
        '*': {
            'respond': 'js/respond.min',
            'customScript':'js/customscript'
        }
    },
    paths: {
            'bootstrap': 'js/bootstrap.min',
            'owl_carousel': 'js/owl.carousel',
            'custom':'js/custom',
    },
    shim: {
        'bootstrap': {
            'deps': ['jquery']
        },
        'owl_carousel': {
            'deps': ['jquery']
        },
         'custom': {
            'deps': ['jquery']
        },
    }
};

 

 

app/design/frontend/Vendor/Theme/Magento_Theme/web/js/customscript.js

define('jquery', function($) { //Your code here //alert('Here'); }(jQuery) ); 

 

 

Our template will call our script: app/design/frontend/Vendor/Theme/Magento_Theme/templates/custom_js.phtml

<script>// <![CDATA[ require([ 'jquery', 'customScript' ], function ($, script) { //Your code here //alert('Here'); }); // ]]> </script>

 

 

Clear Magento Cache and run static content deploy: php bin/magento setup:static-content:deploy

 

Comments

Popular posts from this blog

Magento 2: Category list for custom magento system configuration section ( Backend )

In system.xml file field for multi select of category is like: NOTE: Use Select for Single item and multiselect for multiple in - <field id = "bannerlist" translate = "label" type = " multiselect " <group id = "bannerblock_setting" translate = "label" type = "text" delault = "1" sortOrder = "3" showInDefault = "1" showInWebsite = "1" showInStore = "1" > <label> Setting </label> <field id = "bannerlist" translate = "label" type = "multiselect" sortOrder = "10" showInDefault = "1" showInWebsite = "1" showInStore = "1" > <label> Select Category </label> <!-- <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>--> <source_model> Ipragmatech\Bannerblock\Model\Config\Source\C...

Magento 2: Add new tab in Product detail page

New tab in product detail page is very easy task with product attribute. Use below steps and check it out. Step 1. Create Product Attribute “video”. Step 2. Create file “ catalog_product_view.xml ” in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layout In the file write the below code: <!-- this is code to add new tab start --> <referenceBlock name="product.info.details"> <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.video" template="product/view/attribute.phtml" group="detailed_info"> <arguments> <argument name="at_call" xsi:type="string">getVideo</argument> <argument name="at_code" xsi:type="string">video</argument> <argument name="css_class" xsi:type="string">video</argument> <argument name="at_label" xsi:type="string">non...