How to Use different logos based on profile in Salesforce Community?

 1. Create a custom component for Theme layout.

<aura:component implements="forceCommunity:themeLayout" controller="UserInfoController">
    <aura:attribute name="search" type="Aura.Component[]" required="false"/>
    <aura:attribute name="profileMenu" type="Aura.Component[]" required="false"/>
    <aura:attribute name="navBar" type="Aura.Component[]" required="false"/>
    <aura:attribute name="footer" type="Aura.Component[]" />
    <aura:attribute name="imgSrcVal" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <div class="slds">
        <div class="slds-grid slds-grid_vertical-align-center">
            <div class="slds-size_1-of-4">
                <img src="{!v.imgSrcVal}"/>
            <div class="slds-size_3-of-4 slds-grid slds-wrap">
                <div class="slds-size_2-of-3">
                <div class="slds-size_1-of-3">
                <div class="slds-size_3-of-3">
        <div class="mainContentArea">
        <footer id="footer">

     init : function(component, event, helper) {
        let action = component.get( "c.fetchUser" );
        action.setCallback( this, function( response ) {
            let state = response.getState();
            if ( state === "SUCCESS" ) {
                let strResponse = response.getReturnValue();
                   console.log( 'Profile is ' + strResponse.Profile.Name );
                switch( strResponse.Profile.Name ) {
                    case "Community User":
                    component.set( "v.imgSrcVal", $A.get( '$Resource.CommunityUser' ) );
                    case "Community Plus User":
                    component.set( "v.imgSrcVal", $A.get( '$Resource.CommunityPlusUser' ) );
                    component.set( "v.imgSrcVal", $A.get( '$Resource.StandardUser' ) );
        $A.enqueueAction( action );

Apex Class:
public class UserInfoController {
    public static user fetchUser() {
        User objUser = [ SELECT Id, Profile.Name, UserRole.Name FROM User Where id =: userInfo.getUserId() ];
        return objUser;
2. Create Custom Theme using the Aura Component.
3. Use the Custom Theme layout for the page.

4. Store the images(logos) in Static Resources.


Here the logo is Standard User since I logged in as System Administrator.

No comments:

Post a Comment