0

I want to create the view more's button. I have:

app/design/frontend/{Name}/{theme}/Magento_Catalog/layout/catalog_product_view.xml

<referenceContainer name="product.info.main">
...
<block class="Magento\Framework\View\Element\Template" name="description.more.js" as="description" template="product/js.phtml"/>
...

app/design/frontend/{Name}/{theme}/requirejs-config.js

var config = {
    map: {
        '*' : {
            'descriptioncontent' : 'js/descriptioncontent',
        }
    }
};

app/design/frontend/{Name}/{theme}/web/js/descriptioncontent.js

define('jquery', function($) {    
    $.fn.ContentManagement = function() {
        alert('Here');
    }
}(jQuery));

app/design/frontend/{Name}/{theme}/Magento_Catalog/templates/product/js.phtml

<script>
// <![CDATA[
    require([
        'jquery',
        'description'
    ], function ($) {
        $(function () { // to ensure that code evaluates on page load
            alert('Check js.phtml');
            $('.product-info-main').ContentManagement();
        });
    });
// ]]>
</script>

For the moment i only have "alerts" to know if the files are correct, but i don't see nothing

1 Answer 1

1

In your template file, try to replace module name description with descriptioncontent.

app/design/frontend/{Name}/{theme}/Magento_Catalog/templates/product/js.phtml

<script>
// <![CDATA[
    require([
        'jquery',
        'descriptioncontent'
    ], function ($) {
        $(function () { // to ensure that code evaluates on page load
            alert('Check js.phtml');
            $('.product-info-main').ContentManagement();
        });
    });
// ]]>
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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