0

I am currently trying to override a register.phml from a custom module in my own custom module.

My modules name is UV_Mitgliedsnummer, the custom module I want to override the template from is Clarion_CustomAttribute.

magento/app/code/UV/Mitgliedsnummer/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">
        <preference for="Magento\Customer\Block\Form\Register" type="Vendor\Module\Block\Form\Register" />
    </config>

magento/app/code/UV/Mitgliedsnummer/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="UV_Mitgliedsnummer" setup_version="1.1.0">
        <sequence>
            <module name="Clarion_CustomAttribute" />
        </sequence>
    </module>
</config>

magento/app/code/UV/Mitgliedsnummer/view/frontend/layout/customer_account_create.xml

<?xml version="1.0"?>
<block class="Magento\Customer\Block\Form\Register" as="virtual" template="form/register.phtml">

<!--
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="clarion.register">
            <arguments>
                <argument name="template" xsi:type="string">Clarion_CustomAttribute::view.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
-->

magento/app/code/UV/Mitgliedsnummer/view/frontend/templates/form/register.phtml

Ich bin ein Test. :-)

Do you have any suggestions why it is not working? Thanks :-)

Edit: It seems to work now but I get these exceptions.

Exception #0 (Magento\Framework\Exception\LocalizedException): Ungültiger Block-Typ: Magento\Customer\Block\Form\Register

Exception #1 (ReflectionException): Class Vendor\Module\Block\Form\Register does not exist
  • in layout file try changing template="form/register.phtml" to template="UV_Mitgliedsnummer::form/register.phtml" – Piyush Feb 27 '18 at 10:12
  • You have not added Block file with class you have defined for your template in xml Or you have assigned wrong class name in xml – Piyush Feb 27 '18 at 10:25
  • Sorry I am new to Magento. Can you describe more detailled and which files you mean? Thanks so far ! – k33n Feb 27 '18 at 10:40
1

You can use below code in xml file to override template

<referenceBlock name="block-name">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">UV_Mitgliedsnummer::form/register.phtml</argument>
    </action>
</referenceBlock>

Note: Change "block-name" as per your modules layout structure

  • How can I find the block name? Clarion_CustomAttributes is a custom module. When I turn dev mode on, it shows me this as block: Magento\Customer\Block\Form\Register – k33n Feb 27 '18 at 11:06
  • it will be there in the Clarion_CustomAttribute module's xml file which your are overriding – Piyush Feb 27 '18 at 11:07
  • <code> <?xml version="1.0"?> <referenceBlock name="customer_form_register"> <action method="setTemplate"> <argument name="template" xsi:type="string">UV_Mitgliedsnummer::form/register.phtml</argument> </action> </referenceBlock> </code> doesn't work :-/ – k33n Feb 27 '18 at 11:23
  • The module xml I am overriding is overriding some module too. It is also referencing to "customer_form_register". May that be the problem? – k33n Feb 27 '18 at 11:33
  • <page xmlns:xsi="w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_form_register"> <action method='setTemplate'> <argument name='template' xsi:type='string'>Clarion_CustomerAttribute::form/register.phtml</argument> </action> </referenceBlock> </body> </page> – k33n Feb 27 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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