Knowledge Base

Programmable Layouts: Channel & Microsite Information

Last Modified:
14 Dec 2018
User Level:
Power User

Introduction

With Programmable Layouts, you can retrieve information about the current Channel or Microsite that your content is in. This can be useful when you want to set dependencies within the content or retrieve the settings used in the Channel configuration. 

Information

This is a list of the common methods used for Channels and Microsites.

get Channel Object

Using publishCache it is possible to retrieve the current Channel configuration. If the code is placed inside a Microsite, it will return the Channel configuration of the Microsite.

(Channel) Channel publishCache.getChannel();Examplechannel = publishCache.getChannel(); document.write(channel);

The result of the above code is:

Channel [id=38, name=Knowledge Base : https://docs.terminalfour.com/, description=Channel for our support, community and knowledge base site, type=text/kb, default_language=en]

get Channel ID

It is possible retrieve the Channel ID using the following method:

(Integer) channel.getID()Examplechannel = publishCache.getChannel() var myChannelID = channel.getID(); document.write('Channel ID: ' + myChannelID + '<br/>');

The result of the above code is:

Channel ID: 38

get Channel Name

If you want the Channel name the following function will get it for you:

channel.getName()Examplechannel = publishCache.getChannel() var myChannelName= channel.getName(); document.write('Channel Name: ' + myChannelName + '<br/>');

The result of the above code is:

Channel Name: Knowledge Base : https://docs.terminalfour.com/

get Channel Publish URL

Requires ver 8.2.7+

When using Open Graph meta tags it can be useful to retrieve the Channel Publish URL for use in the og:url property:

(string) channel.getChannelPublishURL()Examplechannel = publishCache.getChannel() var myChannelURL = channel.getChannelPublishURL(); document.write('Channel Publish URL: ' + myChannelURL + '<br/>');

The result of the above code is:

Channel Publish URL: https://docs.terminalfour.com/

get Channel Default Content Layout

The Channel Content Layout is useful when interacting with Content Layout information.

(string) channel.getType()Examplechannel = publishCache.getChannel() var myChannelType = channel.getType(); document.write('Channel Default Content Layout: ' + myChannelType + '<br/>');

The result of the above code is:

Channel Default Content Layout: text/kb

get Channel Default Fulltext Content Layout

Similar to the Channel Default Content Layout, the fulltext default layout will be useful when working with content and Content Layout information:

(string) channel.getFullTextType();Examplechannel = publishCache.getChannel() var myChannelType = channel.getFullTextType(); document.write('Channel Default Fulltext Content Layout: ' + myChannelType + '<br/>');

The result of the above code is:

Channel Default Fulltext Content Layout: text/kb/fulltext

get Microsite Channel

This method requires a CachedSection Object. See Section Information for more details.

In TERMINALFOUR, Microsites are simplified Channel. When retrieving the Microsite information a Channel Object will be returned. It is then possible to retrieve the specific information using the functions already seen in this page.

Name
Type
Global Variable
Description 
Section CachedSection section It is the information of the Section that needs to check if is a Microsite
(Channel) publishCache.getMicroSiteFromChild((CachedSection) mySection);Examplevar sectionID = section.getID(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(publishCache.getChannel(), section, sectionID, language); var myMicrosite = publishCache.getMicroSiteFromChild(mySection); if(myMicrosite){ document.write('Microsite Information of <a href="' + myMicrosite.getChannelPublishURL() + '">' + myMicrosite.getChannelPublishURL() + '</a> ID : ' + myMicrosite.getID() + '<br/>'); } else { document.write('The section ' + sectionID +' is not in a microsite'+ '<br/>'); }

The result of the above code is:

The section 10441 is not in a microsite