1

Namespace/Modulename/Block/donation.php

namespace Namespace\Modulename\Block;

class Productpoint extends \Magento\Framework\View\Element\Template
{

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }


}

Namespace/Modulename/view/frontend/web/templates/checkout/cart/donation.phtml

<span><?php echo 'Eureka'; ?></span>

Rewrite checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Namespace\Modulename\Block\Productpoint" before="-" template="Namespace_Modulename::checkout/cart/productpoint.phtml"/>
        </referenceContainer>
    </body>
</page>

The block is not loading on cart page. How do I call my custom block on cart page?

1
  • How about your issue? Commented Nov 12, 2016 at 5:42

2 Answers 2

1

First of all, your phtml is wrong path, remove web folder, it should be: Namespace/Modulename/view/frontend/templates/checkout/cart/donation.phtml

Second, Your block is wrong name: Namespace/Modulename/Block/donation.php => Namespace/Modulename/Block/Productpoint.php

Third, you can add your block to the containers such items and no items or additional block info. Your template will be rendered automatically.

And your template="Namespace_Modulename::checkout/cart/productpoint.phtml should be checkout/cart/donation.phtml.

checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="with-items">
            <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" 
              template="Namespace_Modulename::checkout/cart/donation.phtml"/>
        </referenceContainer>
        <referenceContainer name="no-items">
            <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" 
              template="Namespace_Modulename::checkout/cart/donation.phtml"/>
        </referenceContainer>

        <referenceBlock name="additional.product.info">
            <block class="Namespace\Modulename\Block\Productpoint" name="custom.block" before="-" 
              template="Namespace_Modulename::checkout/cart/donation.phtml"/>
        </referenceBlock>
    </body>
</page>
8
  • There has been an error processing your request Exception printing is disabled by default for security reasons.a:4:{i:0;s:37:"Object DOMDocument should be created.";i:1;s:12986:"#0 D:\xampp\htdocs\m202s\vendor\magento\framework\View\Element\UiComponent\Config\Reader.php(95): Magento\Framework\View\Element\UiComponent\Config\DomMerger->getDom() #1 D:\xampp\htdocs\m202s\vendor\magento\module-ui\Model\Manager.php(261): Magento\Framework\View\Element\UiComponent #2 D:\xampp\htdocs\m202s\vendor\magento\module-ui\Model\Manager.php(169): Magento\Ui\Model\Manager->prepare('additional.prod...') Commented Nov 9, 2016 at 13:17
  • @parasarora1303 try this: magento.stackexchange.com/questions/93783/… Commented Nov 9, 2016 at 13:23
  • I am currently working on local magento on windows and it is having proper permissions . even I had remove pub/static inner folder and also all folder of var and run php bin/setup:static-content:deploy Commented Nov 9, 2016 at 13:26
  • Your template checkout/cart/productpoint.phtml or checkout/cart/donation.phtml? I have just updated my answer. Commented Nov 9, 2016 at 13:31
  • my template is productpoint.phtml Commented Nov 9, 2016 at 13:33
1

You have put your phtml file at wrong place,Follow Below path

Namespace/Modulename/view/frontend/templates/checkout/cart/donation.phtml After doing so clear your cache and run static content deploy. It should work.

Your Answer

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

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