Skip to main content

How do I configure a conditional header? (MT4)

UndefinedNameError: reference to undefined name 'linkedinurl_damien' (click for details)
Callstack:
    at (Documentation/MindTouch4/Branding/FAQs/How_do_I_configure_a_conditional_header?), /content/body/pre, line 5, column 12


MindTouch self-service branding allows you to customize the header, footer and side tray of your MindTouch site.  In some situations, you may want to display a different header to particular users or on particular pages.  This article demonstrates how to configure multiple user or page headers and display them dynamically based on the user or page. 
 

What is a Custom Header?

A custom header is a branding region within your MindTouch site that you can use to brand your MindTouch site.  Your custom header is a MindTouch template and can be located by going to Site Tools > Templates.  Typically you custom header is located at:

  • Templates > Custom > Views > Header
    • Path:    /Template:Custom/Views/Header

You can add HTML, CSS, JavaScript and DekiScript to your custom header which provides a lot of flexibility for adding dynamic layout. 

How does a Conditional Header work?

template_structure_dynamic_header.pngThe dynamic custom header is quite a simple structure.  Basically, you have a standard MindTouch header which has code to determine if it should dynamically embed content from another page which we call "Conditional Headers".  

For instance, the Header node in the diagram to the left would use DekiScript to:

  1. Get the page path (success.yoursite.com/path/path/path)
  2. Determine if it should dynamically embed a Conditional Header
  3. Uses a DekiScript function to load the Conditional Header 

 

Example Logic

If the page path is /Documentation then load the header at /Template:Custom/View/Header/Documentation.

Note: Conditional headers are not supported on Special Pages such as Search, Login Screen and Password Screen. Special pages only support one default header.

How do I structure my Conditional Header Templates?

header_template_dynamic_layout.pngWhen you're getting ready to configure your conditional header, you will need to create a MindTouch template for each variation of the header.  By default, you should have a header template located at Custom > Views > Header.  

Tip:  If you do not have a header template at this location, contact a MindTouch Customer Success Agent to get self-service branding setup.  

Once you have located your Header Template, you should create a separate page for each Conditional Header.  The diagram to the right shows the template structure that is used at success.mindtouch.com.  Make sure you add some content into your header to indicate which header is loading.  

Note: If you find yourself creating more than six, you may want to reconsider your approach. More than ten conditional headers will be hard to manage and may have performance complications. 

How do I dynamically display a header for different paths?

Once you have properly setup your conditional header template structure, you can begin to wire up the logic.  In the following example, we give you an IF statement to dynamically load one of the conditional headers.   You will need to add the following DekiScript to you header template location at Custom > Views > Header.

// GET THE PAGE PATH AND SPLIT IT BY FORWARD SLASHES
// EXAMPLE PATH = /Documentation/Administration/Analyzing_Knowledge
// SPLIT PATH = [ "Documentation", "Administration", "Analyzing_Knowledge" ]
var current = string.split(page.path,"/");


// GET THE FIRST ITEM IN THE PATH LIST
var section = current[0];


// TEST THE CONDITIONS AND EMBED THE CONDITIONAL HEADER USING A TEMPLATE() CALL. 
if (#current && section == "Contact_Us")
{
   template("Custom/Views/Header/Contact_Us");
}
if (#current && section == "Documentation")
{
    template("Custom/Views/Header/Documentation");
}

How do I dynamically display a header for different user groups?

You can also add a conditional header based on a user group.  This scenario would essentially allow you to show a different headers for people in different groups regardless or what the page path was.  For instance, you may want your developer  to have links to more technical resources or you may want users in the contributor group to be reminded of your technical writing standards.

You can simply create a developer and contributor group and add users accordingly.  Then, add the following DekiScript to your Custom header located at Templates > Custom > Views > Header. 

// TEST THE CONDITIONS AND EMBED THE CONDITIONAL HEADER USING A TEMPLATE() CALL.
if (user.groups["developer"])
{
    template("Custom/Views/Header/Developer");
}
if (user.groups["contributor"])
{
    template("Custom/Views/Header/Contributor");
}