0
Vendor\magento\module-customer\view\frontend\templates\widget\name.phtml

override into my custom module

mycompany\custommodule\view\frontend\templates\widget\name.phtml

but I can't override this phtml file . If any one knows, help me?

5
  • Try creating your custom theme and simply copy the file to your theme folder. Check the following link, magento.stackexchange.com/questions/132177/…
    – MGento
    Commented Nov 7, 2017 at 4:53
  • this file is not setting from layout file. you need to override block Magento\Customer\Block\Widget Commented Nov 7, 2017 at 5:01
  • how to override block and if there is need any layout file?
    – Mahi M
    Commented Nov 7, 2017 at 5:08
  • you can achieve with plugin or preference Commented Nov 7, 2017 at 5:29
  • i want preference method to override this
    – Mahi M
    Commented Nov 8, 2017 at 13:31

1 Answer 1

1

Follow below steps to override vendor/magento/module-customer/view/frontend/templates/widget/name.phtml file

app/code/Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Customer\Block\Widget\Name">
        <plugin name="custom_widget_name" type="Vendor\Module\Plugin\Customer\Block\Widget\Name" />
    </type>

</config>

app/code/Vendor/Module/Plugin/Customer/Block/Widget/Name.php

<?php

namespace Vendor\Module\Plugin\Customer\Block\Widget;
class Name
{
    public function after_construct(\Magento\Customer\Block\Widget\Name $result)
    {

        $result->setTemplate('Vendor_Module::widget/name.phtml');
        return $result;
    }
}
?>

Now copy vendor/magento/module-customer/view/frontend/templates/widget/name.phtml and paste into app/code/Vendor/Module/view/frontend/templates/widget/name.phtml

4
  • Please explain overiding in preference method(without using plugin)
    – Mahi M
    Commented Nov 8, 2017 at 13:29
  • Plugin is better than preference. Why do you want to override with preference method? Commented Nov 8, 2017 at 19:07
  • ok.i want to override \Magento\Customer\Model\ResourceModel\AddressRepository .. for hide lastname validation.
    – Mahi M
    Commented Nov 9, 2017 at 4:35
  • Did you know about this? magento.stackexchange.com/questions/255630/… Commented Dec 24, 2018 at 6:30

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.