cancel
Showing results for 
Search instead for 
Did you mean: 

how to use phtml blocks and variables in another phtml with in same module ? magento 2

how to use phtml blocks and variables in another phtml with in same module ? magento 2

Hi guys,

              i have two files which is in same module i.e module_sales.

path :1

vendor/magento/module-sales/view/frontend/templates/order/items/renderer/default.phtml

code :

$block \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer */
$_item = $block->getItem();

Note : i want to access above block and variable in below file i.e items.phtml .

path:2

vendor/magento/module-sales/view/frontend/templates/email/items.phtml

 

how can i access can anyone guide me ?

4 REPLIES 4

Re: how to use phtml blocks and variables in another phtml with in same module ? magento 2

while declaring in the layout file call the same block class but give different names with different templates.

 

Example:

<referenceContainer name="content">
    <block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer" name="items_name" template="order/items/renderer/default.phtml" />
<block after="content" class=
"Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer" name="another_name" template="email/items.phtml" />
</referenceContainer>

Thanks!! 

Re: how to use phtml blocks and variables in another phtml with in same module ? magento 2

i do used the below mentioned way . can you tell  me is this correct or not ?

 

layout file for default.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="sales.order.items.renderers">
<block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer" name="items2_name" template="email/items.phtml" />

<block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer" name="sales.order.items.renderers.default" as="default" template="Magento_Sales:Smiley Surprisedrder/items/renderer/default.phtml"/>
</referenceBlock>
</body>
</page>

layout file for items.phtml


<block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer" name="items2_name" template="email/items.phtml" />

 

<block class="Magento\Sales\Block\Order\Email\Items" name="items" template="Magento_Sales::email/items.phtml"

Re: how to use phtml blocks and variables in another phtml with in same module ? magento 2

is this throwing any error?

Re: how to use phtml blocks and variables in another phtml with in same module ? magento 2

Check reference from below blog might be helpful for you,

https://www.rakeshjesadiya.com/how-to-override-magento-2-order-items-renderer-default-phtml/

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial