Skip to main content
added 89 characters in body
Source Link
Pawan
  • 6k
  • 2
  • 17
  • 38

You can download module at GitHub

You can download module at GitHub

added 147 characters in body
Source Link
Pawan
  • 6k
  • 2
  • 17
  • 38
  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
     \Magento\Framework\Component\ComponentRegistrar::register(
         \Magento\Framework\Component\ComponentRegistrar::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/StoreinfoSiteinfo.php

     <?php
     namespace Vendor\Siteinfo\Block;
     class Siteinfo extends \Magento\Framework\View\Element\Template
     {    
     public function __construct(
         \Magento\Backend\Block\Template\Context $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="Vendor\Siteinfo\Block\Siteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}

  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
     \Magento\Framework\Component\ComponentRegistrar::register(
         \Magento\Framework\Component\ComponentRegistrar::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/Storeinfo.php

     <?php
     namespace Vendor\Siteinfo\Block;
     class Siteinfo extends \Magento\Framework\View\Element\Template
     {    
     public function __construct(
         \Magento\Backend\Block\Template\Context $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

  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
     \Magento\Framework\Component\ComponentRegistrar::register(
         \Magento\Framework\Component\ComponentRegistrar::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 Vendor\Siteinfo\Block;
     class Siteinfo extends \Magento\Framework\View\Element\Template
     {    
     public function __construct(
         \Magento\Backend\Block\Template\Context $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="Vendor\Siteinfo\Block\Siteinfo" name="site-info" as="site-info" template="Vendor_Siteinfo::storename.phtml" }}

Source Link
Pawan
  • 6k
  • 2
  • 17
  • 38

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
     \Magento\Framework\Component\ComponentRegistrar::register(
         \Magento\Framework\Component\ComponentRegistrar::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/Storeinfo.php

     <?php
     namespace Vendor\Siteinfo\Block;
     class Siteinfo extends \Magento\Framework\View\Element\Template
     {    
     public function __construct(
         \Magento\Backend\Block\Template\Context $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