How to show different logo when the user is logged in?
-
follow this answer and in helper check customer is login or not then pass logo path as per your need– PiyushCommented Jan 5, 2018 at 16:25
-
can you give me more details please– user3005390Commented Jan 5, 2018 at 16:29
-
what more details you need? if you follow that answer you will achieve what you need with little modifications– PiyushCommented Jan 5, 2018 at 16:30
-
so i replace <arguments> <argument name="logo_file" xsi:type="string">images/logo.png</argument> <argument name="logo_img_width" xsi:type="number">192</argument> <!--<argument name="logo_img_height" xsi:type="number">50</argument>--> </arguments> with <argument name="logo_file" xsi:type="helper" helper="Namespace\ModuleName\Helper\Data::getLogoImage"></argument> where i can find helper file?– user3005390Commented Jan 5, 2018 at 16:35
-
1Sorry friend I am little bit busy, will surely help you when I get some time.– PiyushCommented Jan 5, 2018 at 16:51
|
Show 2 more comments
1 Answer
You can set different logo while customer is logged in using a helper method, You have to Create a custom module for this.
In your layout you have to pass helper method for logo path,By adding below code in file
Magento_Theme/layout/default.xml
<argument name="logo_file" xsi:type="helper" helper="Namespace\ModuleName\Helper\Data::getLogoImage"></argument>
After that in your modules helper file you have to add below code
<?php
namespace Namespace\ModuleName\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $_request;
protected $_session;
public function __construct
(
\Magento\Framework\App\Request\Http $request,
\Magento\Customer\Model\Session $session
) {
$this->_request = $request;
$this->_session = $session;
}
public function getLogoImage()
{
if ($this->_session->isLoggedIn()) {
$logo = 'path/to/logo/for/logged_in/customer.png';
} else {
$logo = 'path/to/logo/for/guest/customer.png';
}
return $logo;
}
}
Note: Change Namespace and ModuleName based on your custom Module
-
-
@BenCrook in that case we have to replace logo path with storeConfig value– PiyushCommented Jan 8, 2018 at 15:14
-
is there a step by step procedure easy to use to achieve this objective? Commented Jan 10, 2018 at 16:08
-
@Piyush Can you please explain how we can call it from logo.phtml or through block, and where to define this argument inside the block or some refrenceBlock? Thankyou Commented May 15, 2018 at 12:17
-
@Piyush I have done it through using the helper object in logo.phtml file. Commented May 15, 2018 at 12:58