Using Magento 2.3.0 with php7.1
I'm trying to use this module to get store information.
I have modified the folder names as such
app/code/Vendor/SiteInfo/Block/SiteInfo.php
And used the following code in SiteInfo.php
<?php
namespace Vendor\SiteInfo\Block;
class SiteInfo extends \Magento\Framework\View\Element\Template
{
protected $_storeManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
)
{
$this->_storeManager = $storeManager;
parent::__construct($context, $data);
}
/**
* Get store identifier
*
* @return int
*/
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
/**
* Get website identifier
*
* @return string|int|null
*/
public function getWebsiteId()
{
return $this->_storeManager->getStore()->getWebsiteId();
}
/**
* Get Store code
*
* @return string
*/
public function getStoreCode()
{
return $this->_storeManager->getStore()->getCode();
}
/**
* Get Store name
*
* @return string
*/
public function getStoreName()
{
return $this->_storeManager->getStore()->getName();
}
/**
* Get current url for store
*
* @param bool|string $fromStore Include/Exclude from_store parameter from URL
* @return string
*/
public function getStoreUrl($fromStore = true)
{
return $this->_storeManager->getStore()->getCurrentUrl($fromStore);
}
/**
* Check if store is active
*
* @return boolean
*/
public function isStoreActive()
{
return $this->_storeManager->getStore()->isActive();
}
}
?>
This is where I need help, it then says
Using the following script in the .phtml file and print the store information.
echo $block->getStoreId() . '<br />';
echo $block->getStoreCode() . '<br />';
echo $block->getWebsiteId() . '<br />';
echo $block->getStoreName() . '<br />';
echo $block->getStoreUrl() . '<br />';
echo $block->isStoreActive() . '<br />';
I tried using it directly in the page using
<?php echo $block->getStoreName() . '<br />';?>
that just shows
$block->getStoreName() . '
';
So how do I go about this, for example if I want to show the "Store name" in a page or a block I've created from the admin panel, how do I go about using the echo script.
Update:
I've created a file
storename.phtml
in
app/code/Vendor/Siteinfo/view/frontend/templates
With this code
<?php
/** @var \Vendor\ModuleName\Block\Hello $block */
?>
<?php
echo $block->getStoreName();
?>
and used this block on a page from admin panel
{{block class="Vendor\SiteInfo\Block\SiteInfo" name="site-info" as="site-info" template="Vendor_SiteInfo::storename.phtml" }}
flushed magento cache, and get this error
"We're sorry, an error has occurred while generating this content."
This is module I have created, that is at this path
app/code
Vendor
instead ofWebsite
?