In magento 2, the theme folder is inside the module. We don't have to write the code in separate theme folder location outside the core module files folder.
Create a module as per the blog post. Create a view folder inside the module. The structure of the folder, is as given below.
VendorName
ModuleName
view
adminhtml
layout
sales_order_view.xml
templates
sales
order
view
custom.phtml
frontend
layout
sales_order_view.xml
templates
sales
order
view
custom.phtml
The theme for the adminhtml and frontend are now, inside the view folder. Magento will automatically process the layout and get the template files and add to the theme. The folder contains layout and templates same as the old magento theme folder. But, now the tags are replaced by individual xml files. Here, have used the sales_order_view.xml file to add custom block to the sales_order/view page.
Sample code for the sales_order_view.xml file.
<?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="order_totals">
<block class="VendorName\ModuleName\Block\Adminhtml\Sales\Order\Custom" name="custom_order_totals" template="VendorName_ModuleName::sales/order/view/custom.phtml">
<action method="setBeforeCondition">
<argument name="condition" xsi:type="string">tax</argument>
</action>
</block>
</referenceBlock>
</body>
</page>
The code for the custom.phtml will be similar to the magento 1 code.
Comments
Post a Comment