简体   繁体   中英

How to pass .phtml file variable to another module .phtml file in magento2

I am new in the magento. If anyone have idea how to do this then please let me know. I have two files in different module in in that two .phtml file will be there. From First .phtml file to another .phtml file i want pass array variable I am not getting how to pass that.

First file path as follows with php variable:

/var/www/html/MyProject/app/design/frontend/Megnor/mag110246_4/Lof_CustomerMembership/templates/customer/membership/transactions.phtml

In this file i have $transaction variable that i want to send another info.phtml

<?php
/** @var \Magento\Customer\Block\Account\Dashboard\Address $block */

$helper = $this->helper("Lof\CustomerMembership\Helper\Data");
$transactions = $block->getTransactions();
$address=$block->getPrimaryBillingAddress();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerId =$customerSession->getCustomer()->getId();
 $activeOrNot="";
?>

Another file path will be:

/var/www/html/MyProject/app/design/frontend/Megnor/mag110246_4/Magedelight_SMSProfile/templates/account/dashboard/info.php

In the info.php file i want that $transactions array variable

Anyone have idea how to do this then please let me know

Your getTransactions() function inside in your block. so just reuse the block for your another phtml file.

Three options,

  1. just copy your function from transactions block to info block, all related variables and constructions too.

  2. From info block, create object from transactions block and this object to create getTransactions() function

  3. Simply call it directly using

    $blockObj= $block->getLayout()->createBlock('Company\ModuleName\Block\ClassName');

    echo $blockObj->getTransactions();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM