1

I tried this with my source but not work:

C:\wamp\www\magento\app\code\magento\hello\view\adminhtml\templates\custom\logo.png

2
  • where you want to use that image Jun 24, 2016 at 5:34
  • @PrashantValanda template file in the custom view\adminhtml\templates\custom\form.phtml i want to use it in form.phtml Jun 24, 2016 at 5:44

1 Answer 1

1

Logo Image Width and Logo Image Height is fetched from Configuration Settings (Stores -> Settings -> Configuration -> General -> Design -> Header).

Create a block class of your custom module for example (Magentotwo_LogoImage). Then injected object of Logo block in the constructor of your custom module’s block class. such as

<?php
namespace Magentotwo\LogoImage\Block;
class LogoImage 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();
    }   
}
?>

Then you can easily use your function in template file such as

echo $block->getLogoSrc() . '<br />';
echo $block->getLogoAlt() . '<br />';
echo $block->getLogoWidth() . '<br />';
echo $block->getLogoHeight() . '<br />';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.