Jump to content

Change company logo based on client group


Recommended Posts

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...

  1. uploaded to /assets/img/  - although you can put the images anywhere and adjust the path in the hook...
  2. 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.
  3. 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.
Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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");
Link to comment
Share on other sites

  • 7 months later...

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 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

  • 11 months later...

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");

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated