magento2 새 페이지에 관리자 레이아웃 및 템플릿로드
-
28-09-2020 - |
문제
이 머리를 감쌀 수 없습니다.
이 컨트롤러가 있습니다
namespace Vendor\Gift\Controller\Adminhtml\Gift;
use Magento\Backend\App\Action\Context;
class Index extends \Magento\Backend\App\Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Backend\App\Action\Context $context
*/
public function __construct(
Context $context
) {
parent::__construct($context);
}
public function execute()
{
$resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
return $resultPage;
}
}
.
view / adminhtml / layout / vendor_gift_index.xml의 레이아웃
편집 :
레이아웃을 view / admandhtml / layout / gift_gift_index.xml로 변경 이 대답 후
https://magento.stackexchange.com/a/102800/36102
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<block class="Vendor\Gift\Block\Adminhtml\Gift\Index" name="vendor.gift.index"
template="Vendor_Gift::gift/index.phtml" />
</referenceContainer>
</body>
</page>
.
및 템플릿 파일 :
view/adminhtml/templates/gift/index.phtml
.
및 블록
네임 스페이스 공급 업체 \ GIFT \ BLOCK \ ADMINHTML \ GIFT;
class Index extends \Magento\Backend\Block\Template
{
protected $_template = 'gift/index.phtml';
public function __construct(
\Magento\Backend\Block\Template\Context $context
) {
parent::__construct($context);
}
protected function _toHtml() {
return $this->_template;
}
}
.
페이지에서 내 출력이 표시되는 이유는 무엇입니까?
Vendor_Gift::gift/index.phtml
.
템플릿에서 HTML 대신.정말로 이것에 정말로 갇혀 있으므로 ... 누군가가 도움이 필요합니다.
해결책
파일 이름을 다음과 같이 변경해야합니다.
vendor_gift_index.xml
gift_gift_index.xml
다른 팁
https://magento.stackexchange.com/a/102800/36102
remove
와 결합protected function _toHtml() {
return $this->_template;
}
.
이이 이유를 알지 못했지만 실제로 블록에서 템플릿으로 변수를 전달하고 템플릿의 HTML 내용을 구문 분석합니다. 끔찍한
제휴하지 않습니다 magento.stackexchange