Get Store Information Magento 2.3.0












0














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 VendorSiteInfoBlock;
class SiteInfo extends MagentoFrameworkViewElementTemplate
{
protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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 VendorModuleNameBlockHello $block */
?>
<?php
echo $block->getStoreName();
?>


and used this block on a page from admin panel




{{block class="VendorSiteInfoBlockSiteInfo" 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











share|improve this question
























  • any error in log ?
    – Pawan
    yesterday










  • No error in the logs
    – user2240778
    14 hours ago










  • I have tried your code and it is working. in admin you are using Vendor instead of Website ?
    – Pawan
    12 hours ago










  • I have shared the module I have created above.
    – user2240778
    12 hours ago
















0














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 VendorSiteInfoBlock;
class SiteInfo extends MagentoFrameworkViewElementTemplate
{
protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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 VendorModuleNameBlockHello $block */
?>
<?php
echo $block->getStoreName();
?>


and used this block on a page from admin panel




{{block class="VendorSiteInfoBlockSiteInfo" 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











share|improve this question
























  • any error in log ?
    – Pawan
    yesterday










  • No error in the logs
    – user2240778
    14 hours ago










  • I have tried your code and it is working. in admin you are using Vendor instead of Website ?
    – Pawan
    12 hours ago










  • I have shared the module I have created above.
    – user2240778
    12 hours ago














0












0








0







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 VendorSiteInfoBlock;
class SiteInfo extends MagentoFrameworkViewElementTemplate
{
protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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 VendorModuleNameBlockHello $block */
?>
<?php
echo $block->getStoreName();
?>


and used this block on a page from admin panel




{{block class="VendorSiteInfoBlockSiteInfo" 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











share|improve this question















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 VendorSiteInfoBlock;
class SiteInfo extends MagentoFrameworkViewElementTemplate
{
protected $_storeManager;

public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoStoreModelStoreManagerInterface $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 VendorModuleNameBlockHello $block */
?>
<?php
echo $block->getStoreName();
?>


and used this block on a page from admin panel




{{block class="VendorSiteInfoBlockSiteInfo" 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








magento2 php module magento2.3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 hours ago







user2240778

















asked yesterday









user2240778user2240778

210311




210311












  • any error in log ?
    – Pawan
    yesterday










  • No error in the logs
    – user2240778
    14 hours ago










  • I have tried your code and it is working. in admin you are using Vendor instead of Website ?
    – Pawan
    12 hours ago










  • I have shared the module I have created above.
    – user2240778
    12 hours ago


















  • any error in log ?
    – Pawan
    yesterday










  • No error in the logs
    – user2240778
    14 hours ago










  • I have tried your code and it is working. in admin you are using Vendor instead of Website ?
    – Pawan
    12 hours ago










  • I have shared the module I have created above.
    – user2240778
    12 hours ago
















any error in log ?
– Pawan
yesterday




any error in log ?
– Pawan
yesterday












No error in the logs
– user2240778
14 hours ago




No error in the logs
– user2240778
14 hours ago












I have tried your code and it is working. in admin you are using Vendor instead of Website ?
– Pawan
12 hours ago




I have tried your code and it is working. in admin you are using Vendor instead of Website ?
– Pawan
12 hours ago












I have shared the module I have created above.
– user2240778
12 hours ago




I have shared the module I have created above.
– user2240778
12 hours ago










3 Answers
3






active

oldest

votes


















1














There are mainly 2 issue.





  1. Your Registration.php is placed at wrong place
    Currently it is placed at




    Vendor/Siteinfo/etc/registration.php





it should be:




Vendor/Siteinfo/registration.php





  1. Wrong Vendor name is defined in registration.php


  2. Wrong Vendor name in module.xml



    Please follow below



    Create




    app/code/Vendor/Siteinfo/registration.php




    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    'Vendor_Siteinfo',
    __DIR__
    );



    app/code/Vendor/Siteinfo/etc/module.xml




    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Siteinfo" setup_version="1.0.0">
    </module>





    app/code/Vendor/Siteinfo/Block/Siteinfo.php




    <?php
    namespace VendorSiteinfoBlock;
    class Siteinfo extends MagentoFrameworkViewElementTemplate
    {
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    array $data =
    )
    {
    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();
    }
    }
    ?>



    app/code/Vendor/Siteinfo/view/frontend/templates/storename.phtml




    <?php echo $block->getStoreName(); ?>


    After that you need to run:



    php bin/magento setup:upgrade



    php bin/magento cache:flush




Finally call:




{{block class="VendorSiteinfoBlockSiteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}




You can download module at GitHub






share|improve this answer























  • Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
    – user2240778
    10 hours ago










  • From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
    – user2240778
    10 hours ago










  • Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
    – Pawan
    2 hours ago










  • Thank you very much Pawan, much appreciated, it works! :-)
    – user2240778
    32 mins ago



















0















In order to use the following block scripts

you need to create a template



Example: Create a template hello.phtml to your custom module following the namespace structure below



VendorModuleNameviewfrontendtemplateshello.phtml




<?php
/** @var VendorModuleNameBlockHello $block */
?>
<?php echo $block->getStoreName(); ?>





share|improve this answer





















  • I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
    – user2240778
    yesterday












  • can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
    – magefms
    yesterday



















0














If you want this in block from admin panel.
Call from block or from CMS page like this



{{block class="MynamespaceMymoduleBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::siteinfo.phtml" }}


It will call the function from related class.



Thanks






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257091%2fget-store-information-magento-2-3-0%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    There are mainly 2 issue.





    1. Your Registration.php is placed at wrong place
      Currently it is placed at




      Vendor/Siteinfo/etc/registration.php





    it should be:




    Vendor/Siteinfo/registration.php





    1. Wrong Vendor name is defined in registration.php


    2. Wrong Vendor name in module.xml



      Please follow below



      Create




      app/code/Vendor/Siteinfo/registration.php




      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'Vendor_Siteinfo',
      __DIR__
      );



      app/code/Vendor/Siteinfo/etc/module.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Vendor_Siteinfo" setup_version="1.0.0">
      </module>





      app/code/Vendor/Siteinfo/Block/Siteinfo.php




      <?php
      namespace VendorSiteinfoBlock;
      class Siteinfo extends MagentoFrameworkViewElementTemplate
      {
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      array $data =
      )
      {
      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();
      }
      }
      ?>



      app/code/Vendor/Siteinfo/view/frontend/templates/storename.phtml




      <?php echo $block->getStoreName(); ?>


      After that you need to run:



      php bin/magento setup:upgrade



      php bin/magento cache:flush




    Finally call:




    {{block class="VendorSiteinfoBlockSiteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}




    You can download module at GitHub






    share|improve this answer























    • Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
      – user2240778
      10 hours ago










    • From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
      – user2240778
      10 hours ago










    • Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
      – Pawan
      2 hours ago










    • Thank you very much Pawan, much appreciated, it works! :-)
      – user2240778
      32 mins ago
















    1














    There are mainly 2 issue.





    1. Your Registration.php is placed at wrong place
      Currently it is placed at




      Vendor/Siteinfo/etc/registration.php





    it should be:




    Vendor/Siteinfo/registration.php





    1. Wrong Vendor name is defined in registration.php


    2. Wrong Vendor name in module.xml



      Please follow below



      Create




      app/code/Vendor/Siteinfo/registration.php




      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'Vendor_Siteinfo',
      __DIR__
      );



      app/code/Vendor/Siteinfo/etc/module.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Vendor_Siteinfo" setup_version="1.0.0">
      </module>





      app/code/Vendor/Siteinfo/Block/Siteinfo.php




      <?php
      namespace VendorSiteinfoBlock;
      class Siteinfo extends MagentoFrameworkViewElementTemplate
      {
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      array $data =
      )
      {
      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();
      }
      }
      ?>



      app/code/Vendor/Siteinfo/view/frontend/templates/storename.phtml




      <?php echo $block->getStoreName(); ?>


      After that you need to run:



      php bin/magento setup:upgrade



      php bin/magento cache:flush




    Finally call:




    {{block class="VendorSiteinfoBlockSiteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}




    You can download module at GitHub






    share|improve this answer























    • Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
      – user2240778
      10 hours ago










    • From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
      – user2240778
      10 hours ago










    • Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
      – Pawan
      2 hours ago










    • Thank you very much Pawan, much appreciated, it works! :-)
      – user2240778
      32 mins ago














    1












    1








    1






    There are mainly 2 issue.





    1. Your Registration.php is placed at wrong place
      Currently it is placed at




      Vendor/Siteinfo/etc/registration.php





    it should be:




    Vendor/Siteinfo/registration.php





    1. Wrong Vendor name is defined in registration.php


    2. Wrong Vendor name in module.xml



      Please follow below



      Create




      app/code/Vendor/Siteinfo/registration.php




      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'Vendor_Siteinfo',
      __DIR__
      );



      app/code/Vendor/Siteinfo/etc/module.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Vendor_Siteinfo" setup_version="1.0.0">
      </module>





      app/code/Vendor/Siteinfo/Block/Siteinfo.php




      <?php
      namespace VendorSiteinfoBlock;
      class Siteinfo extends MagentoFrameworkViewElementTemplate
      {
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      array $data =
      )
      {
      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();
      }
      }
      ?>



      app/code/Vendor/Siteinfo/view/frontend/templates/storename.phtml




      <?php echo $block->getStoreName(); ?>


      After that you need to run:



      php bin/magento setup:upgrade



      php bin/magento cache:flush




    Finally call:




    {{block class="VendorSiteinfoBlockSiteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}




    You can download module at GitHub






    share|improve this answer














    There are mainly 2 issue.





    1. Your Registration.php is placed at wrong place
      Currently it is placed at




      Vendor/Siteinfo/etc/registration.php





    it should be:




    Vendor/Siteinfo/registration.php





    1. Wrong Vendor name is defined in registration.php


    2. Wrong Vendor name in module.xml



      Please follow below



      Create




      app/code/Vendor/Siteinfo/registration.php




      <?php
      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'Vendor_Siteinfo',
      __DIR__
      );



      app/code/Vendor/Siteinfo/etc/module.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Vendor_Siteinfo" setup_version="1.0.0">
      </module>





      app/code/Vendor/Siteinfo/Block/Siteinfo.php




      <?php
      namespace VendorSiteinfoBlock;
      class Siteinfo extends MagentoFrameworkViewElementTemplate
      {
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      array $data =
      )
      {
      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();
      }
      }
      ?>



      app/code/Vendor/Siteinfo/view/frontend/templates/storename.phtml




      <?php echo $block->getStoreName(); ?>


      After that you need to run:



      php bin/magento setup:upgrade



      php bin/magento cache:flush




    Finally call:




    {{block class="VendorSiteinfoBlockSiteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}




    You can download module at GitHub







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 11 hours ago

























    answered 12 hours ago









    PawanPawan

    1,6132515




    1,6132515












    • Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
      – user2240778
      10 hours ago










    • From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
      – user2240778
      10 hours ago










    • Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
      – Pawan
      2 hours ago










    • Thank you very much Pawan, much appreciated, it works! :-)
      – user2240778
      32 mins ago


















    • Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
      – user2240778
      10 hours ago










    • From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
      – user2240778
      10 hours ago










    • Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
      – Pawan
      2 hours ago










    • Thank you very much Pawan, much appreciated, it works! :-)
      – user2240778
      32 mins ago
















    Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
    – user2240778
    10 hours ago




    Have done exactly as you have listed, the config end tag was missing on the module.xml, I added that and ran upgrade, the module is enabled under etc/config.php, however I'm getting this error "Error filtering template: Invalid block type: VendorSiteinfoBlockSiteinfo"
    – user2240778
    10 hours ago












    From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
    – user2240778
    10 hours ago




    From exception log [2019-01-09 18:56:02] main.CRITICAL: Invalid block type: VendorSiteinfoBlockSiteinfo {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Invalid block type: Vendor\Siteinfo\Block\Siteinfo at /home/xyz/m230.xyz.com/Vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Vendor\Siteinfo\Block\Siteinfo does not exist at /home/xyz/m230.xyz.com/vendor/magento/framework/Code/Reader/ClassReader.php:19)"}
    – user2240778
    10 hours ago












    Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
    – Pawan
    2 hours ago




    Your block name file should be Siteinfo.php. I have upload module on github, Please download and it. I have tested and it s working.If still have any issue, let me know.
    – Pawan
    2 hours ago












    Thank you very much Pawan, much appreciated, it works! :-)
    – user2240778
    32 mins ago




    Thank you very much Pawan, much appreciated, it works! :-)
    – user2240778
    32 mins ago













    0















    In order to use the following block scripts

    you need to create a template



    Example: Create a template hello.phtml to your custom module following the namespace structure below



    VendorModuleNameviewfrontendtemplateshello.phtml




    <?php
    /** @var VendorModuleNameBlockHello $block */
    ?>
    <?php echo $block->getStoreName(); ?>





    share|improve this answer





















    • I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
      – user2240778
      yesterday












    • can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
      – magefms
      yesterday
















    0















    In order to use the following block scripts

    you need to create a template



    Example: Create a template hello.phtml to your custom module following the namespace structure below



    VendorModuleNameviewfrontendtemplateshello.phtml




    <?php
    /** @var VendorModuleNameBlockHello $block */
    ?>
    <?php echo $block->getStoreName(); ?>





    share|improve this answer





















    • I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
      – user2240778
      yesterday












    • can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
      – magefms
      yesterday














    0












    0








    0







    In order to use the following block scripts

    you need to create a template



    Example: Create a template hello.phtml to your custom module following the namespace structure below



    VendorModuleNameviewfrontendtemplateshello.phtml




    <?php
    /** @var VendorModuleNameBlockHello $block */
    ?>
    <?php echo $block->getStoreName(); ?>





    share|improve this answer













    In order to use the following block scripts

    you need to create a template



    Example: Create a template hello.phtml to your custom module following the namespace structure below



    VendorModuleNameviewfrontendtemplateshello.phtml




    <?php
    /** @var VendorModuleNameBlockHello $block */
    ?>
    <?php echo $block->getStoreName(); ?>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered yesterday









    magefmsmagefms

    32110




    32110












    • I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
      – user2240778
      yesterday












    • can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
      – magefms
      yesterday


















    • I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
      – user2240778
      yesterday












    • can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
      – magefms
      yesterday
















    I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
    – user2240778
    yesterday






    I've created a storename.phtml file in app/code/vendor/Siteinfo/view/frontend/templates With this code <?php /** @var VendorModuleNameBlockHello $block */ ?> <?php echo $block->getStoreName(); ?> and used this block on a page from admin panel {{block class="vendorSiteInfoBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::storename.phtml" }} flushed magento cache, and get this error "We're sorry, an error has occurred while generating this content." Should I run a upgrade from SSH?
    – user2240778
    yesterday














    can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
    – magefms
    yesterday




    can you post your code for the page in admin in your post above. I will check. no need to run upgrade from ssh
    – magefms
    yesterday











    0














    If you want this in block from admin panel.
    Call from block or from CMS page like this



    {{block class="MynamespaceMymoduleBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::siteinfo.phtml" }}


    It will call the function from related class.



    Thanks






    share|improve this answer


























      0














      If you want this in block from admin panel.
      Call from block or from CMS page like this



      {{block class="MynamespaceMymoduleBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::siteinfo.phtml" }}


      It will call the function from related class.



      Thanks






      share|improve this answer
























        0












        0








        0






        If you want this in block from admin panel.
        Call from block or from CMS page like this



        {{block class="MynamespaceMymoduleBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::siteinfo.phtml" }}


        It will call the function from related class.



        Thanks






        share|improve this answer












        If you want this in block from admin panel.
        Call from block or from CMS page like this



        {{block class="MynamespaceMymoduleBlockSiteInfo" name="site-info" as="site-info" template="Magento_Theme::siteinfo.phtml" }}


        It will call the function from related class.



        Thanks







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Sanket KulkarniSanket Kulkarni

        312




        312






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257091%2fget-store-information-magento-2-3-0%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1300-talet

            1300-talet

            Has there ever been an instance of an active nuclear power plant within or near a war zone?