Magento 2 Customer Address – How to Create New Address

customercustomer-addressfrontendmagento2

I'm getting a blank page (without content, sidebars etc exists) on customer/address/new action using an custom theme.

What I want to do is to implement that new page under customer/address/new, that's the standard action when customer has no addresses.

So I've created an xml customer_address_new.xml in which I've specified an template file (and other stuff copied from the edit action), but it doesn't work, I've got same effect as without my layout and template files.

The layout file: <theme>/Magento_Customer/layout/customer_address_new.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">
    <update handle="customer_account" />
    <body>
        <referenceBlock name="head.components">
            <block class="Magento\Framework\View\Element\Js\Components" name="customer_page_head_components" template="Magento_Customer::js/components.phtml" />
        </referenceBlock>
        <referenceBlock name="customer-account-navigation-address-link">
            <arguments>
                <argument name="is_highlighted" xsi:type="boolean">true</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Address\Edit" name="customer_address_new" template="address/new.phtml" cacheable="true" />
        </referenceContainer>
    </body>
</page>

What's going on?

Best Answer

You have missing layout="1column" in your customer_address_new.xml file,

please insert layout inside node,

   <?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">
    <update handle="customer_account" />
    <body>
        <referenceBlock name="head.components">
            <block class="Magento\Framework\View\Element\Js\Components" name="customer_page_head_components" template="Magento_Customer::js/components.phtml" />
        </referenceBlock>
        <referenceBlock name="customer-account-navigation-address-link">
            <arguments>
                <argument name="is_highlighted" xsi:type="boolean">true</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Address\Edit" name="customer_address_new" template="address/new.phtml" cacheable="true" />
        </referenceContainer>
    </body>
</page>