You can override the book.phtml file in Magento 2 using XML.
Book template used to display the address book of the customer with default billing and shipping address at the top of the Address book page.
1 | Magento\Customer\Block\Address\Book |
Book Block class contains the native method for the template.
You can override using theme or module level,
- 1. Theme Level,
- 1app/design/frontend/{Vendor}/{themename}/Magento_Customer/templates/address/book.phtml
- 2. Module Level,
When you explore the customer_address_index.xml file from the customer module, You can see the address_book block that will be used to display the address book page on the frontend.
In your module create the same XML file, app/code/Jesadiya/Book/view/frontend/layout/customer_address_index.xml,
1 2 3 4 5 6 7 8 9 10 | <?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"> <body> <referenceBlock name="address_book"> <action method="setTemplate"> <argument name="template" xsi:type="string">Jesadiya_Book::address/book.phtml</argument> </action> </referenceBlock> </body> </page> |
Create Template file to override book.phtml,
app/code/Jesadiya/Book/view/frontend/templates/address/book.phtml
In the above module, Jesadiya_Book is the Module name for simplicity.
Keep the required content from the Core template and modify your changes. If you want to change an additional section in a page, Override address/grid.phtml in Magento 2.
Clear Cache to see changes,
php bin/magento cache:flush
This is the simplest way to override the address book content in Magento 2.