Al Fahad Anik Posted January 7, 2020 Share Posted January 7, 2020 Hello Staff, is it possible to change company logo based on clients group? like i have 4 different client group. i want to show separate logo for each client based on their clients group. can anyone help me about this. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 8, 2020 Share Posted January 8, 2020 On 07/01/2020 at 06:31, Al Fahad Anik said: is it possible to change company logo based on clients group? yes - either by editing theheader template or using an action hook. On 07/01/2020 at 06:31, Al Fahad Anik said: like i have 4 different client group. i want to show separate logo for each client based on their clients group. the hook below should change the logo based on client groups - it needs to be given a filename (ending in .php) and uploaded to /includes/hooks <?php # Compamy Logo Based On Client Group Hook # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = "assets/img/logo".$groupid.".png"; if (file_exists($logo)) { return array ("assetLogoPath" => $logo); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); it assumes that the logos for each client group are... uploaded to /assets/img/ - although you can put the images anywhere and adjust the path in the hook... the filenames of the logo images are in the format logo{groupID}.png - so the logo for client group #1 will be logo1.png; the logo for client group #2 will be logo2.png and so on. if the logged in client is a member of a client group, and if the image file exists, then the logo variable will be updated to the correct URL - if they are not logged in, or a member of a client group or if the image doesn't exist, then the hook does nothing and the default logo / text will be shown. 3 Quote Link to comment Share on other sites More sharing options...
system53 Posted March 23, 2020 Share Posted March 23, 2020 This source is not working. I need you up to date. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 23, 2020 Share Posted March 23, 2020 7 minutes ago, system53 said: This source is not working. I need you up to date. i've just tested it on v7.9.2 and it's still working fine. are you sure that you've created, and named correctly, all of the logos for your different client groups ?? 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted March 23, 2020 Share Posted March 23, 2020 My codes are as follows. and the logos are in the directory they should be in. Header.tpl <a class="c-sidebar__brand u-ml-small" href="{$systemurl}"> {if $assetLogoPath} <img src="{$WEB_ROOT}/templates/{$template}/assets/img/logo{groupID}.png" alt="{$companyname}"> {else} {$companyname} {/if} </a> ( logo{groupID}.png ) This way the site layout is broken.Website codes are falling apart. ( logo{$groupID}.png ) In this way the site layout is normal but dysfunctional. I uploaded the logos to the hooks directory and theme img directory in the same way. <?php # Compamy Logo Based On Client Group Hook # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = "assets/img/logo".$groupid.".png"; if (file_exists($logo)) { return array ("assetLogoPath" => $logo); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); Hol 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 23, 2020 Share Posted March 23, 2020 Hi @system53 5 minutes ago, system53 said: ( logo{groupID}.png ) This way the site layout is broken.Website codes are falling apart. ( logo{$groupID}.png ) In this way the site layout is normal but dysfunctional. I uploaded the logos to the hooks directory and theme img directory in the same way. the problem here is that the template is not even using the hook - you could delete the hook and the same thing would occur because of the incorrect code in the header.tpl... the hook returns a value for the $assetLogoPath variable based on the current value of the client group - but your code isn't outputting the returned $assetLogoPath value. so your header.tpl should really be... <a class="c-sidebar__brand u-ml-small" href="{$systemurl}"> {if $assetLogoPath} <img src="{$assetLogoPath}" alt="{$companyname}"> {else} {$companyname} {/if} </a> for other users, I did spot an issue with the hook in that it wasn't working on nested pages - e.g the MarketConnect sales pages... so i've tweaked the code a little and it should now show the correct logo (if found) on all pages... <?php # Compamy Logo Based On Client Group Hook v1.1 # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = $vars['systemurl']."/assets/img/logo".$groupid.".png"; $headers = get_headers($logo, 1); if (strpos($headers['Content-Type'], 'image/') !== false) { return array ("assetLogoPath" => $logo); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted March 23, 2020 Share Posted March 23, 2020 yes now this process has been successful. Thank you:) 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted November 2, 2020 Share Posted November 2, 2020 Hi @brian! Will this work with V8 If i plan to use logo path as url ? ----------------------- <?php # Compamy Logo Based On Client Group Hook # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = "assets/img/logo".$groupid.".png"; if (file_exists($logo)) { return array("assetLogoPath" => "https://upload.wikimedia.org/wikipedia/en/c/ce/SVG-logo.svg"); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); ----------------------- Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 2, 2020 Share Posted November 2, 2020 56 minutes ago, VirtualWorldGlobal said: Will this work with V8 If i plan to use logo path as url ? yes - as long as the image file exists in the URL, the hook will change the logo shown based on the client group - regardless of whether the user logging in is an owner or not. the hook isn't changing the URL that the logo links to - that can be done, just not with this particular hook. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted November 2, 2020 Share Posted November 2, 2020 This means that only one logo will be displayed as I will be using the url ? if i have to display multiple logo using url then ? 3 minutes ago, brian! said: the hook isn't changing the URL that the logo links to - that can be done, just not with this particular hook. Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 2, 2020 Share Posted November 2, 2020 2 minutes ago, VirtualWorldGlobal said: This means that only one logo will be displayed as I will be using the url ? good point - the hook wouldn't check that a remote image exists... it's checking that a local image exists, but then not using it (that's a legacy of quickly adapting the hook to use a remote image). 4 minutes ago, VirtualWorldGlobal said: if i have to display multiple logo using url then ? well if they were hosted locally, then it would try to use the correct image for a given client group, e.g if a client from group #1 logged in, it would want to use logo1.png; if a client from group #5 logged in, it would want to use logo5.png etc. but if the images are going to be remote, there's nothing to stop you expanding the if statement to check for different group values, e.g if groupid == 2, use remote image #2 etc if you have a choice of hosting the logos locally, then that would be preferable than making remote calls on every page load. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted November 2, 2020 Share Posted November 2, 2020 So you advise to use the hook with local images yes that would be easier, so do I use the one of your hooks pasted below ? <?php # Compamy Logo Based On Client Group Hook v1.1 # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = $vars['systemurl']."/assets/img/logo".$groupid.".png"; $headers = get_headers($logo, 1); if (strpos($headers['Content-Type'], 'image/') !== false) { return array ("assetLogoPath" => $logo); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 2, 2020 Share Posted November 2, 2020 5 minutes ago, VirtualWorldGlobal said: So you advise to use the hook with local images yes that would be easier, so do I use the one of your hooks pasted below ? yes & yes 2 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted October 15, 2021 Share Posted October 15, 2021 Hi, I have two logos how to use it, Thanks ----- <?php # Compamy Logo Based On Client Group Hook v1.1 # Written by brian! function client_group_logo_hook($vars) { $client = Menu::context('client'); $groupid = $client->groupid; if ($groupid > 0) { $logo = $vars['systemurl']."/assets/img/logo".$groupid.".png"; $headers = get_headers($logo, 1); if (strpos($headers['Content-Type'], 'image/') !== false) { return array ("assetLogoPath" => $logo); } } } add_hook("ClientAreaPage", 1, "client_group_logo_hook"); 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted October 16, 2021 Share Posted October 16, 2021 22 hours ago, ManagedCloud-Hosting said: I have two logos how to use it, Thanks Do you want to use them at the same time or in specific cases? If for specific cases, where it provides the log you just add an "if, then" block to determine which logo to use and what the if looks for depends on what your criteria are. 0 Quote Link to comment Share on other sites More sharing options...
Gabster Posted December 30, 2021 Share Posted December 30, 2021 Hi, I would need similar hook for different logos based on language either FR or EN, Thanks. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.