Add headers to multiple pages (CMS)

NeilH2
Giga Guru

Has anyone ever found a way to add a new header block to multiple pages at once.

 

I have a customer that changes the header a user can see depending on which company they are from, when they need to setup a portal for that customer they add a header with the company logo.

 

Adding the logo to all pages in the site can be difficult and time consuming does anyone know of a way to do this en-mass?

 

I can code this but id rather not, if a workable solution has been used before.

1 ACCEPTED SOLUTION

richard_selby
Kilo Guru

Let me share something I've used for this. When using the ESS portal, suppose you want the top banner (i.e. JC Header block) to change according to the user's company.It should feature a custom logo and slogan if possible. But if no company is set, or the company logo (Banner Image, a pre-existing field) is empty, then the default logo defined in the header should be used. Similarly if no slogan is set on the Company table, the Text field from the generic portal header should be used.



First   added a Slogan (u_slogan) field to the company table.



Then I added a Script Include called cmsExtras Include like so


var cmsExtras = Class.create();


cmsExtras.prototype = {


      initialize: function(companyId) {


  this.defaultSlogan = current.text.getDisplayValue();


  this.defaultLogo = current.logo.getDisplayValue();


      },



  getLogo: function(companyId) {


  var companyLogo;


  if (companyId != null && companyId != '')


  {


  var gr = new GlideRecord('core_company');


  gr.get(companyId);


  companyLogo = gr.banner_image.getDisplayValue();


  }


  if (companyLogo){


  return companyLogo;


  }


  return this.defaultLogo;


  },



  getSlogan: function(companyId) {



  var companySlogan = '';



  if (companyId != null && companyId != '') {


  var gr = new GlideRecord('core_company');


  gr.get(companyId);


  companySlogan = gr.u_slogan.getDisplayValue();


  }


   


  if (companySlogan != '')


        return companySlogan;




  return this.defaultSlogan;


  },



      type: 'cmsExtras'


};



Finally I altered two OOTB UI Macros, cms_header_text and cms_header_logo, to call the script include to figure out what to return: default or company specific logo/slogan.


Below you can see cms_header_text. Line 4 is the only one which has been amended, to replace a hard-coded echoing of ${current.text.getDisplayValue()} in favour of   a call to cmsExtras()


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <div class="cms_header_text">


    <span class="cms_header_text"> ${


    new cmsExtras().getSlogan(gs.getUser().getCompanyID());


    } </span>


  </div>


</j:jelly>



And this is cms_header_logo. Same principle here. Line 6 was previously a call to ${current.logo.getDisplayValue()} but now calls the Script Include, which figures out whether to return the logo in the header block, or the company specific one



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <j:if test="${current.logo.getDisplayValue() != ''}">


        <div class="cms_header_logo" >


            <a href="home.do">


  <img src="${new cmsExtras().getLogo(gs.getUser().getCompanyID())}" alt="{gs.getMessage('Home')}" />  


  </a>


        </div>


  </j:if>


</j:jelly>




This should do the trick. Hope it helps someone.


View solution in original post

4 REPLIES 4

solutioningnow
Giga Guru

Hi Neil,



We have exact implementation running in production, company logo changes with respect to the company of the logged in user.



This can be achievable quickly by adding one image field on the company and altering one macro, below are the steps.



Steps:


1) Create a field 'u_logo' on company table with data type as image. Load all images w.r.t company.


2) Open a macro 'cms_header_logo' and override below code.



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<g:evaluate>


    var user = gs.getUser();


    var company = new GlideRecord ('core_company');


    company.get(user.getCompanyID());


    company.query();


</g:evaluate>


<j:if test="${company.next()}">


  <div class="cms_header_logo" >


      <a href="home.do"><img src="${company.u_logo.getDisplayValue()}"/></a>


              </div>


</j:if>


<--


<j:if test="${current.logo.getDisplayValue() != ''}">


        <div class="cms_header_logo" >


            <a href="home.do"><img src="${current.logo.getDisplayValue()}" alt="${current.text}" /></a>


        </div>


</j:if>


-->


</j:jelly>



You are all set, good to go.



Please mark answer as correct/helpful, if it was really helpful 🙂




Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


Mahira
Tera Guru

Hi Neil,



Were you able to figure this out? I too have a similar situation.



Regards,


Mahira


Hi Mahira



I wasn't, work on this area stopped soon after the post and i've not had a chance to revisit it.


Solutioneers idea looks viable but i've never been able to test it.


richard_selby
Kilo Guru

Let me share something I've used for this. When using the ESS portal, suppose you want the top banner (i.e. JC Header block) to change according to the user's company.It should feature a custom logo and slogan if possible. But if no company is set, or the company logo (Banner Image, a pre-existing field) is empty, then the default logo defined in the header should be used. Similarly if no slogan is set on the Company table, the Text field from the generic portal header should be used.



First   added a Slogan (u_slogan) field to the company table.



Then I added a Script Include called cmsExtras Include like so


var cmsExtras = Class.create();


cmsExtras.prototype = {


      initialize: function(companyId) {


  this.defaultSlogan = current.text.getDisplayValue();


  this.defaultLogo = current.logo.getDisplayValue();


      },



  getLogo: function(companyId) {


  var companyLogo;


  if (companyId != null && companyId != '')


  {


  var gr = new GlideRecord('core_company');


  gr.get(companyId);


  companyLogo = gr.banner_image.getDisplayValue();


  }


  if (companyLogo){


  return companyLogo;


  }


  return this.defaultLogo;


  },



  getSlogan: function(companyId) {



  var companySlogan = '';



  if (companyId != null && companyId != '') {


  var gr = new GlideRecord('core_company');


  gr.get(companyId);


  companySlogan = gr.u_slogan.getDisplayValue();


  }


   


  if (companySlogan != '')


        return companySlogan;




  return this.defaultSlogan;


  },



      type: 'cmsExtras'


};



Finally I altered two OOTB UI Macros, cms_header_text and cms_header_logo, to call the script include to figure out what to return: default or company specific logo/slogan.


Below you can see cms_header_text. Line 4 is the only one which has been amended, to replace a hard-coded echoing of ${current.text.getDisplayValue()} in favour of   a call to cmsExtras()


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <div class="cms_header_text">


    <span class="cms_header_text"> ${


    new cmsExtras().getSlogan(gs.getUser().getCompanyID());


    } </span>


  </div>


</j:jelly>



And this is cms_header_logo. Same principle here. Line 6 was previously a call to ${current.logo.getDisplayValue()} but now calls the Script Include, which figures out whether to return the logo in the header block, or the company specific one



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <j:if test="${current.logo.getDisplayValue() != ''}">


        <div class="cms_header_logo" >


            <a href="home.do">


  <img src="${new cmsExtras().getLogo(gs.getUser().getCompanyID())}" alt="{gs.getMessage('Home')}" />  


  </a>


        </div>


  </j:if>


</j:jelly>




This should do the trick. Hope it helps someone.