I've been trying to add some php logic to view the things I want. I found out that the proper way to do this using a block template in a .phtml file in the /view/frontend/templates folder of the module.

What I've tried

In my module's layout(checkout_index_index.xml) file added this:

<referenceContainer name="content">
      <block class="DeliveryMatch\Shipping\Block\DmCarrier" name="dm-shipping" template="DeliveryMatch_Shipping::checkout/shipping/carrier_custom.phtml" before="shippingAdditional" cacheable="false" />

To display the contents of the .phtml before shippingAdditional


namespace DeliveryMatch\Shipping\Block\DmCarrier;

use Magento\Framework\View\Element\Template;

class DmCarrier extends \Magento\Framework\View\Element\Template

    public function __construct(Template\Context $context, array $data = array())
        parent::__construct($context, $data);


And the .phtml file in


<h1><?php echo 'Test'; ?></h1>

But this is not displayed in the checkout.

What I need

Display the contents of


Inside the shippingAdditional field

How do I achieve this?

Thanks in advance

2 Answers 2


Then you can use it

echo $this->getLayout()->createBlock("DeliveryMatch\Shipping\Block\DmCarrier\DmCarrier")->setTemplate("DeliveryMatch_Shipping::checkout/shipping/carrier_custom.phtml")->toHtml();
  • In what file can I use this? And where to setup the file so it's used by the checkout?
    – Dion
    Commented Jun 19, 2018 at 12:09

You can insert your block into other template file '.phtml' of checkout.

<div style="" class="col-md-12 with-padleft">
    echo $this->getLayout()
  • In what file is this? Can you include the file path?
    – Dion
    Commented Jun 19, 2018 at 12:08
  • For example. if you want to add your block in 'module-checkout/view/frontend/templates/onepage.phtml' you need to copy this file into your module ''DeliveryMatch' that look like 'DeliveryMatch/view/frontend/templates/onepage.phtml' Commented Jun 20, 2018 at 2:18

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.