Hi I create a custom module that lets people who are logged in and have an attribute shows a button. I would like to do it all from the extension without touching the default.xml. I would like to reference the container and place a block inside of it but it does not seem to be working. Here is the block:
<?php
namespace WorldSynergy\LoginPortal\Block;
use Magento\Customer\Model\Url;
use Magento\Framework\App\Http\Context;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Model\ResourceModel\Order\Customer\Collection;
{
class Portal extends Template
{
protected $_customerUrl;
protected $_customer;
protected $httpContext;
/**
* Constructor
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Model\ResourceModel\Order\Customer\Collection $customer,
Url $customerUrl,
Context $httpContext,
array $data = []
) {
$this->_customer = $customer;
$this->_customerUrl = $customerUrl;
$this->httpContext = $httpContext;
parent::__construct($context, $data);
}
/**
* @return string
*/
public function isLoggedIn()
{
if $this->$_customer->create()->addAttributeToSelect('is_allowed',array('eq'=>1)) {
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
}
}
here is the layout file located at vendor/namespace/view/frontend/layout
<?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>
<referenceContainer name="header.container">
<block as="portal" class="vendor\namespace\Block\Portal" name="portal" template="vendor_namespce::portal.phtml"/>
</referenceContainer>
</body>
</page>
here is the custom .phtml file just saying hello now.
<?php
/**
*/
?>
<div>
<?=// $block->isLoggedIn() ?>
hello
</div>
for some reason it is not placing it in the container and was wondering if some could point me to the right place.
here is the defualt.xml
<?xml version="1.0"?>
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="default_head_blocks"/>
<body>
<!-- Inline scripts -->
<referenceContainer name="before.body.end">
<block class="Magento\Translation\Block\Js" name="translate" template="Magento_Translation::translate.phtml"/>
<block class="Magento\Framework\View\Element\Js\Cookie" name="js_cookies" template="Magento_Theme::js/cookie.phtml"/>
<block class="Magento\Theme\Block\Html\Notices" name="global_notices" template="html/notices.phtml"/>
<block class="Magento\Framework\View\Element\Template" name="theme.js" before="-" template="Magento_Theme::jsconfigurator.phtml" />
<block class="Magento\Framework\View\Element\Template" name="theme_child.js" before="-" template="Magento_Theme::jsconfigurator_child.phtml" />
</referenceContainer>
<!-- Inline scripts END -->
<!-- Header. RD-Navbar -->
<referenceContainer name="header.container">
<container name="rd.navbar-wrap" htmlTag="div" htmlClass="rd-navbar">
<container name="rd.navbar" htmlTag="div" htmlClass="rd-navbar-panel layout_1" />
</container>
</referenceContainer>
<referenceBlock name="skip_to_content" remove="true" />
<!-- Header. RD-Navbar END -->
<!-- Navbar Collapse -->
<block class="Magento\Framework\View\Element\Template" name="navbar.collapse" template="Magento_Theme::rd-navbar-collapse.phtml"/>
<move element="navbar.collapse" destination="rd.navbar.collapse" before="-" />
<!-- Navbar Collapse End -->
<!-- Header Panel -->
<referenceContainer name="header.panel" htmlClass="panel page-header__panel">
<container name="header.panel.grid-container" htmlClass="container" htmlTag="div" before="-">
<container name="header.switchers" htmlClass="header-switchers" htmlTag="div" before="-"/>
<container name="panel.container.wrap" htmlClass="panel-container-wrap" htmlTag="div"/>
</container>
</referenceContainer>
<!-- Header Panel END -->
<!-- Header Content -->
<referenceContainer name="header-wrapper" htmlClass="page-header__content">
<container name="header-wrapper.grid-container" htmlClass="container" htmlTag="div" before="-"/>
</referenceContainer>
<!-- Header Content END -->
<!-- Navbar Collapse -->
<container name="rd.navbar.collapse" htmlClass="rd-navbar-collapse-container" htmlTag="div" after="-">
<container name="rd.navbar.collapse.items" htmlClass="rd-navbar-collapse" htmlTag="div">
<block class="Magento\Store\Block\Switcher" name="store_language_mobile" as="store_language" template="switch/languages_mobile.phtml"/>
<block class="Magento\Directory\Block\Currency" name="currency_mobile" before="store_language" template="currency_mobile.phtml" after="store_language_mobile"/>
</container>
</container>
<move element="top.links" destination="rd.navbar.collapse.items"/>
<!-- Navbar Collapse End -->
<referenceBlock name="navigation.sections" remove="true" />
Any help is appreciated and thanks!