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?
-
How about your issue?Khoa Truong– Khoa Truong2016年11月12日 05:42:10 +00:00Commented Nov 12, 2016 at 5:42
2 Answers 2
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>
-
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...')Paras Arora– Paras Arora2016年11月09日 13:17:05 +00:00Commented Nov 9, 2016 at 13:17
-
@parasarora1303 try this: magento.stackexchange.com/questions/93783/…Khoa Truong– Khoa Truong2016年11月09日 13:23:51 +00:00Commented 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:deployParas Arora– Paras Arora2016年11月09日 13:26:33 +00:00Commented Nov 9, 2016 at 13:26
-
Your template
checkout/cart/productpoint.phtmlorcheckout/cart/donation.phtml? I have just updated my answer.Khoa Truong– Khoa Truong2016年11月09日 13:31:18 +00:00Commented Nov 9, 2016 at 13:31 -
my template is productpoint.phtmlParas Arora– Paras Arora2016年11月09日 13:33:17 +00:00Commented Nov 9, 2016 at 13:33
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.