3

Namespacee/Modulename/Block/Productpoint.php

<?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/layout/checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <body>
        <referenceContainer name="content">
            <block template="checkout/cart/productpoint.phtml" class="Namespace\Modulename\Block\Productpoint" name="productpoints.cart.block" as="productpointblock" before="-"/>
        </referenceContainer>
    </body>
</page>

Namespace/Modulename/view/frontend/templates/checkout/cart/productpoint.phtml

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

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

2
  • check system.log in var/log folder and _prepareLayout() function is not needed
    – ND17
    Commented Mar 3, 2016 at 11:35
  • Is the template rendering correctly? If not it may be worth trying to add the namespace and module name before the template like so: <block template="Namespace_Modulename::checkout/cart/productpoint.phtml"
    – Ben Crook
    Commented Mar 3, 2016 at 15:11

1 Answer 1

10

Rewrite checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" 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>

Now the block will be displayed on top of shopping cart.

2
  • system.log says main.CRITICAL: Invalid method Ei\Productpoint\Block\Productpoint::__(Array ( [0] => Redeem Credit Points )) I have already removed _prepareLayout method Commented Mar 3, 2016 at 12:19
  • you can restore _prepareLayout method and check
    – Mike
    Commented Mar 3, 2016 at 12:39

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.