I have created a custom module. When we click on the admin grid to edit, it opens edit page. In that I am showing tabs. When I click on that tab I need to show template file. If you see the below screen you can get ideaenter image description here
this is my tab file
 <?php
/**
 /**
 * Exinent_Customerids Module 
 *
 * @category customer
 * @package 
 * @author pawan
 *
 */
namespace Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab;
/**
 * customerid post edit form main tab
 */
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
class Meat extends \Magento\Backend\Block\Template
{
// const IBAN_TEMPLATE = 'Exinent_Customerids::test.phtml';
 protected $_template = 'test.phtml';
 protected $_coreRegistry = null;
// public function __construct(
// \Magento\Backend\Block\Widget\Context $context,
// array $data = []
// ) {
// parent::__construct($context, $data);
// }
// protected function _prepareLayout()
// {
// parent::_prepareLayout();
// if (!$this->getTemplate()) {
// $this->setTemplate(static::IBAN_TEMPLATE);
// }
//
// return $this;
// }
}
my layout file
<block class="Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab\Meat" name="customerids_customerids_edit_tab_meat"/>
 <arguments>
 <argument name="config" xsi:type="array">
 <item name="label" xsi:type="string" translate="true">customerids_customerids_edit_tab_meat</item>
 <item name="collapsible" xsi:type="boolean">true</item>
 <item name="opened" xsi:type="boolean">true</item>
 <item name="sortOrder" xsi:type="string">2</item>
 <item name="canShow" xsi:type="boolean">true</item>
 <item name="componentType" xsi:type="string">fieldset</item>
 </argument>
 </arguments>
- 
 Please share the what you tried so farAmit Bera– Amit Bera ♦2018年08月10日 10:53:06 +00:00Commented Aug 10, 2018 at 10:53
- 
 @AmitBera I have updated my questionPawankumar– Pawankumar2018年08月10日 12:46:39 +00:00Commented Aug 10, 2018 at 12:46
- 
 magento.stackexchange.com/questions/217621/… followed this link also process alsoPawankumar– Pawankumar2018年08月10日 13:03:38 +00:00Commented Aug 10, 2018 at 13:03
2 Answers 2
- You need to confirm that, you create - test.phtmlfile at this location.
 - Vendor\Modulename\view\adminhtml\templates\test.phtml
- You need to replace _prepareLayout function code like this. - <?php namespace Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab; use Magento\Backend\Block\Template\Context; use Magento\Framework\Registry; class Meat extends \Magento\Backend\Block\Template { protected function _prepareLayout() { $customhtml = parent::_prepareLayout(); $customhtml .= $this->setTemplate('Vendor_Modulename::test.phtml')->toHtml(); return $customhtml; } }
- 
 How can we access variables defined in prepareLayout function to template file?Khushbu– Khushbu2019年07月12日 12:35:08 +00:00Commented Jul 12, 2019 at 12:35
- 
 @Khushbu please ask the seprate question so you get your answer.Dhiren Vasoya– Dhiren Vasoya2019年07月12日 12:42:23 +00:00Commented Jul 12, 2019 at 12:42
- 
 Asked on magento.stackexchange.com/questions/281901/…Khushbu– Khushbu2019年07月12日 12:57:37 +00:00Commented Jul 12, 2019 at 12:57
1.In the layout file you can add the code :
<referenceContainer name="left">
 <block class="Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab" name="customerids_customerids_edit_tab">
 <block class="Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab\Child" name="customerids_customerids_edit_tab_child"/> 
 <action method="addTab">
 <argument name="name" xsi:type="string">child_section</argument>
 <argument name="block" xsi:type="string">customerids_customerids_edit_tab_child</argument>
 </action> 
 </block>
</referenceContainer>
2.Create the new file on the path :
Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab\Child.php
With content :
namespace Vendor\Modulename\Block\Adminhtml\Customerids\Edit\Tab;
class Child extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
 /**
 * @var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset
 */
 protected $_rendererFieldset;
 /**
 * @var \Magento\Store\Model\System\Store
 */
 protected $_systemStore;
 protected $_customerFactory; 
 protected $_resource; 
 /**
 * @param \Magento\Backend\Block\Template\Context $context
 * @param \Magento\Framework\Registry $registry
 * @param \Magento\Framework\Data\FormFactory $formFactory
 * @param \Magento\Store\Model\System\Store $systemStore
 * @param array $data
 */
 public function __construct(
 \Magento\Backend\Block\Template\Context $context,
 \Magento\Framework\Registry $registry,
 \Magento\Framework\Data\FormFactory $formFactory,
 \Magento\Store\Model\System\Store $systemStore,
 \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
 \Magento\Customer\Model\CustomerFactory $customerFactory, 
 \Magento\Framework\App\ResourceConnection $resource, 
 array $data = []
 ) {
 $this->_systemStore = $systemStore;
 $this->_rendererFieldset = $rendererFieldset;
 $this->_customerFactory = $customerFactory; 
 $this->_resource = $resource; 
 parent::__construct($context, $registry, $formFactory, $data);
 }
 /**
 * Prepare form
 *
 * @return $this
 */
 protected function _prepareForm()
 {
 /* @var $model \Magefan\Blog\Model\Category */
 $model = $this->_coreRegistry->registry('current_model');
 /*
 * Checking if user have permissions to save information
 */
 $isElementDisabled = !$this->_isAllowedAction('Vendor_Modulename::child');
 /** @var \Magento\Framework\Data\Form $form */
 $form = $this->_formFactory->create();
 $form->setHtmlIdPrefix('child_');
 $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Add Your Child')]);
 if ($model->getId()) {
 $fieldset->addField('id', 'hidden', ['name' => 'id']);
 }
 $fieldset->addField(
 'html', 
 'text', 
 [
 'name' => 'html',
 'label' => __('Html Content'),
 'title' => __('Html Content'),
 'required' => true,
 'disabled' => $isElementDisabled 
 ]
 )->setRenderer($this->_rendererFieldset->setTemplate('Vendor_Modulename::child.phtml')); 
 if (!$model->getId()) {
 $model->setData('status', $isElementDisabled ? '0' : '1');
 } 
 $this->_eventManager->dispatch('vendor_modulename_edit_tab_main_prepare_form', ['form' => $form]);
 $form->setValues($model->getData());
 $this->setForm($form);
 return parent::_prepareForm();
 }
 /**
 * Prepare label for tab
 *
 * @return \Magento\Framework\Phrase
 */
 public function getTabLabel()
 {
 return __('Html Content');
 }
 /**
 * Prepare title for tab
 *
 * @return \Magento\Framework\Phrase
 */
 public function getTabTitle()
 {
 return __('Html Content');
 }
 /**
 * Returns status flag about this tab can be shown or not
 *
 * @return bool
 */
 public function canShowTab()
 {
 return true;
 }
 /**
 * Returns status flag about this tab hidden or not
 *
 * @return bool
 */
 public function isHidden()
 {
 return false;
 }
 /**
 * Check permission for passed action
 *
 * @param string $resourceId
 * @return bool
 */
 protected function _isAllowedAction($resourceId)
 {
 return $this->_authorization->isAllowed($resourceId);
 }
}
3.Create file :
Vendor/Modulename/view/adminhtml/templates/child.phtml
And put your content here
Hope it helps !
- 
 How can we access variables defined in prepareForm function to template file?Khushbu– Khushbu2019年07月12日 10:51:46 +00:00Commented Jul 12, 2019 at 10:51