In Magento 2, I can retrieve the logo image url by using this:
public function __construct(\Magento\Theme\Block\Html\Header\Logo $_logo){
$logUrl = $_logo->getLogoSrc();
}
Is there a way to retrieve logo full directory image path ?
Step 1: Create a module with the required files. Dolphin_HelloWorld
Step 2: Create block app/code/Dolphin/HelloWorld/Block/HelloWorld.php
You will use a block class of the module Dolphin_HelloWorld, then possibly inject the object of Logo class in the constructor of the module’s block class.
<?php
namespace Dolphin\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
protected $_logo;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Theme\Block\Html\Header\Logo $logo,
array $data = []
)
{
$this->_logo = $logo;
parent::__construct($context, $data);
}
/**
* Get logo image URL
*
* @return string
*/
public function getLogoSrc()
{
return $this->_logo->getLogoSrc();
}
/**
* Get logo text
*
* @return string
*/
public function getLogoAlt()
{
return $this->_logo->getLogoAlt();
}
/**
* Get logo width
*
* @return int
*/
public function getLogoWidth()
{
return $this->_logo->getLogoWidth();
}
/**
* Get logo height
*
* @return int
*/
public function getLogoHeight()
{
return $this->_logo->getLogoHeight();
}
}
?>
Step 2: Get Logo data in template (.phtml) file
Add the below function in your template (.phtml) file
echo $block->getLogoSrc() . '<br />';
echo $block->getLogoAlt() . '<br />';
echo $block->getLogoWidth() . '<br />';
echo $block->getLogoHeight() . '<br />';
Thanks,