Knowledge Base

Programmable Layouts: Section Information

Last Modified:
14 Dec 2018
User Level:
Power User

Introduction

You can use Programmable Layouts to get Section information for the current Section, specific Sections, the parent Section, or grandparent Section.

Methods

The following is a list of common methods you can use to retrieve information about Sections.

section (get Current Cached Content)

section is a global variable that returns the CachedSection Object of the current Section.

(CachedSection) sectionExampledocument.write(section);

The results of the above code is:

Section ------- id: 10443 status: 0 - en: Programmable Layouts: Section Information 1542639114000 my content ---------- sequence: 1 Content ------- id: 37409 - en: cur: Programmable Layouts: Section Information:4.0:0:1544780792000:279:0, name: help link value: , name: site manager min user level value: 48:433, name: keywords value: , name: keywords-t4-extended-muscl-en value: app: Programmable Layouts: Section Information:4.0:0:1544780792000:279:0, name: help link value: , name: site manager min user level value: 48:433, name: keywords value: , name: keywords-t4-extended-muscl-en value: sequence: 3 Content ------- id: 37410 - en: cur: get CachedSection:7.0:0:1544628371000:279:0 app: get CachedSection:7.0:0:1544628371000:279:0 sequence: 2 Content ------- id: 37412 - en: cur: section:3.0:0:1544628371000:279:0 app: section:3.0:0:1544628371000:279:0 sequence: 4 Content ------- id: 37413 - en: cur: Get Section ID:2.0:0:1544628371000:279:0 app: Get Section ID:2.0:0:1544628371000:279:0 sequence: 5 Content ------- id: 37414 - en: cur: Get Section Name:3.0:0:1544628371000:279:0 app: Get Section Name:3.0:0:1544628371000:279:0 sequence: 6 Content ------- id: 37415 - en: cur: Get Section Level:3.0:0:1544628371000:279:0 app: Get Section Level:3.0:0:1544628371000:279:0 sequence: 7 Content ------- id: 37416 - en: cur: get Section Path (URL link):4.0:0:1544628371000:279:0 app: get Section Path (URL link):4.0:0:1544628371000:279:0 sequence: 8 Content ------- id: 37417 - en: cur: Get Section System Directory:2.0:0:1544628371000:279:0 app: Get Section System Directory:2.0:0:1544628371000:279:0 sequence: 9 Content ------- id: 37419 - en: cur: Get All Content from a Section excluding system Content Types:3.0:0:1544628371000:279:0 app: Get All Content from a Section excluding system Content Types:3.0:0:1544628371000:279:0 sequence: 10 Content ------- id: 37420 - en: cur: Get All Content from a section including system content types:2.0:0:1542645682000:326:0 app: Get All Content from a section including system content types:2.0:0:1542645682000:326:0 sequence: 11 Content ------- id: 37421 - en: cur: Get Parent Section:1.0:0:1542645774000:326:0 app: Get Parent Section:1.0:0:1542645774000:326:0 sequence: 12 Content ------- id: 37422 - en: cur: get Grand Parent Section:1.0:0:1542645837000:326:0 app: get Grand Parent Section:1.0:0:1542645837000:326:0 sequence: 13 Content ------- id: 37423 - en: cur: Get all Parent Sections:1.0:0:1542645887000:326:0 app: Get all Parent Sections:1.0:0:1542645887000:326:0 sequence: 14 Content ------- id: 37424 - en: cur: Get SEO Key Phrases:1.0:0:1542645960000:326:0 app: Get SEO Key Phrases:1.0:0:1542645960000:326:0 sequence: 15 Content ------- id: 37425 - en: cur: Get Page Layout of a section:1.0:0:1542646020000:326:0 app: Get Page Layout of a section:1.0:0:1542646020000:326:0 sequence: 17 Content ------- id: 37686 - en: cur: Related Links:1.0:0:1544628596000:279:0 app: Related Links:1.0:0:1544628596000:279:0 sequence: 16 Content ------- id: 37432 - en: cur: Programmable Layouts: Section Information:2.0:0:1544629469000:279:0 app: Programmable Layouts: Section Information:2.0:0:1544629469000:279:0

get CachedSection

To retrieve the cached information of a specific Section should be used the following mode.

Name
Type
Global Variable
Description 
section CachedSection section The current Section information.
channel Channel publishCache.getChannel() The Channel configuration.
sectionID integer   The ID of the Section that
we want to retrieve the cache information
language string language The language information (e.g. 'en')
(CachedSection) com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language);Examplevar sectionID = section.getID() var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); document.write(mySection);

The results of the above code is:

Section ------- id: 10443 status: 0 - en: Programmable Layouts: Section Information 1542639114000 my content ---------- sequence: 1 Content ------- id: 37409 - en: cur: Programmable Layouts: Section Information:4.0:0:1544780792000:279:0, name: help link value: , name: site manager min user level value: 48:433, name: keywords value: , name: keywords-t4-extended-muscl-en value: app: Programmable Layouts: Section Information:4.0:0:1544780792000:279:0, name: help link value: , name: site manager min user level value: 48:433, name: keywords value: , name: keywords-t4-extended-muscl-en value: sequence: 3 Content ------- id: 37410 - en: cur: get CachedSection:7.0:0:1544628371000:279:0 app: get CachedSection:7.0:0:1544628371000:279:0 sequence: 2 Content ------- id: 37412 - en: cur: section:3.0:0:1544628371000:279:0 app: section:3.0:0:1544628371000:279:0 sequence: 4 Content ------- id: 37413 - en: cur: Get Section ID:2.0:0:1544628371000:279:0 app: Get Section ID:2.0:0:1544628371000:279:0 sequence: 5 Content ------- id: 37414 - en: cur: Get Section Name:3.0:0:1544628371000:279:0 app: Get Section Name:3.0:0:1544628371000:279:0 sequence: 6 Content ------- id: 37415 - en: cur: Get Section Level:3.0:0:1544628371000:279:0 app: Get Section Level:3.0:0:1544628371000:279:0 sequence: 7 Content ------- id: 37416 - en: cur: get Section Path (URL link):4.0:0:1544628371000:279:0 app: get Section Path (URL link):4.0:0:1544628371000:279:0 sequence: 8 Content ------- id: 37417 - en: cur: Get Section System Directory:2.0:0:1544628371000:279:0 app: Get Section System Directory:2.0:0:1544628371000:279:0 sequence: 9 Content ------- id: 37419 - en: cur: Get All Content from a Section excluding system Content Types:3.0:0:1544628371000:279:0 app: Get All Content from a Section excluding system Content Types:3.0:0:1544628371000:279:0 sequence: 10 Content ------- id: 37420 - en: cur: Get All Content from a section including system content types:2.0:0:1542645682000:326:0 app: Get All Content from a section including system content types:2.0:0:1542645682000:326:0 sequence: 11 Content ------- id: 37421 - en: cur: Get Parent Section:1.0:0:1542645774000:326:0 app: Get Parent Section:1.0:0:1542645774000:326:0 sequence: 12 Content ------- id: 37422 - en: cur: get Grand Parent Section:1.0:0:1542645837000:326:0 app: get Grand Parent Section:1.0:0:1542645837000:326:0 sequence: 13 Content ------- id: 37423 - en: cur: Get all Parent Sections:1.0:0:1542645887000:326:0 app: Get all Parent Sections:1.0:0:1542645887000:326:0 sequence: 14 Content ------- id: 37424 - en: cur: Get SEO Key Phrases:1.0:0:1542645960000:326:0 app: Get SEO Key Phrases:1.0:0:1542645960000:326:0 sequence: 15 Content ------- id: 37425 - en: cur: Get Page Layout of a section:1.0:0:1542646020000:326:0 app: Get Page Layout of a section:1.0:0:1542646020000:326:0 sequence: 17 Content ------- id: 37686 - en: cur: Related Links:1.0:0:1544628596000:279:0 app: Related Links:1.0:0:1544628596000:279:0 sequence: 16 Content ------- id: 37432 - en: cur: Programmable Layouts: Section Information:2.0:0:1544629469000:279:0 app: Programmable Layouts: Section Information:2.0:0:1544629469000:279:0

Get Section ID

As already seen in the example above, the ID is used to retrieve the main Cached Section information. Sometimes this information will be hardcoded in the Content Layout. You can retrieve the ID from a CachedSection object:

(integer) section.getID()Examplevar mySectionID = section.getID(); document.write('Section ID: ' + mySectionID + '<br/>');

The results of the above code is:

Section ID: 10443<br/>

Get Section Name

You can retrieve the Section name ussing the following method:

Name
Type
Global Variable
Description 
language string language it is the language information (e.g. 'en')
(string) mySection.getName((string) language)Examplevar sectionID = section.getID() var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var mySectionName = mySection.getName(language); document.write('Section name: ' + mySectionName + '<br/>');

The results of the above code is:

Section name: Programmable Layouts: Section Information<br/>

Get Section Level

This method will retrieve the level of Section in Site Structure where Level=1 is the root Section (or home Section) of the current Channel.

Name
Type
Global Variable
Description 
channel Channel publishCache.getChannel() it is the channel configuration.
(integer) mySection. getLevel(channel);Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var mySectionLevel = mySection. getLevel(channel); document.write('Section level: ' + mySectionLevel + '<br/>');

The results of the above code is:

Section level: 5<br/>

get Section Path (URL link)

if passed isPreview always = false, it will always return the published URL, if instead it will pass isPreview=true, it will always output the preview URL. When passed isPreview it will change depends on the Publish or Preview Mode

To retrieve the path of the Section used to create a link you can use the following function:

Name
Type
Global Variable
Description 
oStmt Statement dbStatement  Retrieves information about
the DB information
oSrc CachedSection section The source Section information
oDest CachedSection    The destination Section information 
oCache PublishCache publishCache The Channel configuration.
language string language The language information (e.g. 'en')
fPreview boolean isPreview True if in Preview mode, false otherwise
(PublishLink) com.terminalfour.publish.PathBuilder.getLink(dbStatement, section, mySection, publishCache,language,isPreview); (string) PublishLink.getLink();Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myLinkObject = com.terminalfour.publish.PathBuilder.getLink(dbStatement, section, mySection, publishCache,language,isPreview); var mySectionPath = myLinkObject.getLink(); document.write('Section Path: ' + mySectionPath + '<br/>'); var sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myLinkObject = com.terminalfour.publish.PathBuilder.getLink(dbStatement, section, mySection, publishCache,language,false); var mySectionPath = myLinkObject.getLink(); document.write('Section Published Path: ' + mySectionPath + '<br/>'); var sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myLinkObject = com.terminalfour.publish.PathBuilder.getLink(dbStatement, section, mySection, publishCache,language,true); var mySectionPath = myLinkObject.getLink(); document.write('Section Preview Path: ' + mySectionPath + '<br/>');

The results of the above code is:

Section Path: /documentation/developer-resources/programmable-layouts/programmable-layouts-section-information/<br/>Section Published Path: /documentation/developer-resources/programmable-layouts/programmable-layouts-section-information/<br/>Section Preview Path: https://websites.terminalfour.com/terminalfour/preview/38/en/10443<br/>

Get Section System Directory

To retrieve the system directory of a Section used to create a link you can use the following function.
publishCache and language are global variables. Instead, mySection is the cachedSection 

(string) com.terminalfour.publish.PathBuilder.getDirectory(mySection, publishCache, language)Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var currentOutputDir = com.terminalfour.publish.PathBuilder.getDirectory(mySection, publishCache, language); document.write('Section System Directory:' + currentOutputDir.toString());

The results of the above code is:

Section System Directory:/terminalfour/shared/htdocs/kb-stage.terminalfour.com/htdocs/documentation/developer-resources/programmable-layouts/programmable-layouts-section-information/

Get All Content from a Section excluding system Content Types

To get all content present in a Section you have to consider if you need just the normal one or you want to include system ones, like Section Meta Description or Access Control. The following method is to retrieve only the relevant one excluding those content used by the system.

Name
Type
Global Variable
Description 
channel Channel publishCache.getChannel() The Channel configuration.
language string  language The language information (e.g. 'en') 
mode integer   See Content Mode
fIncludeFutureContent boolean  false  If false future content will be excluded.
This will take the Publish Date information 
(cachedContent[]) com.terminalfour.sitemanager.cache.utils.CSHelper.extractCachedContent( com.terminalfour.sitemanager.cache.utils.CSHelper.removeSpecialContent(mySection.getContent(channel, language, mode, false))); Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var mode = isPreview ? com.terminalfour.sitemanager.cache.CachedContent.CURRENT : com.terminalfour.sitemanager.cache.CachedContent.APPROVED; var mySectionContent = com.terminalfour.sitemanager.cache.utils.CSHelper.extractCachedContent(com.terminalfour.sitemanager.cache.utils.CSHelper.removeSpecialContent(mySection.getContent(channel, language, mode, false))); for (prop in mySectionContent) { myContentID = mySectionContent[prop].getID(); var contentManager = com.terminalfour.spring.ApplicationContextProvider.getBean(com.terminalfour.content.IContentManager); var myContent = contentManager.get(myContentID,language); var myContentType = publishCache.getTemplate(dbStatement, myContent.getContentTypeID()); var myContentTypeType = myContentType.getTemplateType() == 30 ? '<span class="badge badge-danger">System</span>' : '<span class="badge badge-info">Normal</span>'; document.write('Content: ' + myContent.getName() + '(ID ' + mySectionContent[prop].getID() + ') ' + ' - <small>Content Type:' + myContentType.getName() + '</small> ' + myContentTypeType + '<br />'); }

The results of the above code is:

java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(java.lang.Class)] or the variable arity signatures [(java.lang.Class, java.lang.Object...)] of the method com.terminalfour.spring.ApplicationContextProvider.getBean match the argument types [jdk.dynalink.beans.StaticClass]

Get All Content from a section including system content types

To get instead all list of contents in a sections without exclusions will use the following method:

Name
Type
Global Variable
Description 
channel Channel publishCache.getChannel() it is the channel configuration.
language string  language it is the language information (e.g. 'en') 
mode integer   See Content Mode
fIncludeFutureContent boolean  false  If false future cotntent will be 
excluded. This will take the 
 information 
(cachedContent[]) com.terminalfour.sitemanager.cache.utils.CSHelper.extractCachedContent(mySection.getContent(channel, language, mode, false));Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var mode = isPreview ? com.terminalfour.sitemanager.cache.CachedContent.CURRENT : com.terminalfour.sitemanager.cache.CachedContent.APPROVED; var mySectionContent = com.terminalfour.sitemanager.cache.utils.CSHelper.extractCachedContent(mySection.getContent(channel, language, mode, false)); for (prop in mySectionContent) { myContentID = mySectionContent[prop].getID(); var contentManager = com.terminalfour.spring.ApplicationContextProvider.getBean(com.terminalfour.content.IContentManager); var myContent = contentManager.get(myContentID,language); var myContentType = publishCache.getTemplate(dbStatement, myContent.getContentTypeID()); var myContentTypeType = myContentType.getTemplateType() == 30 ? '<span class="badge badge-danger">System</span>' : '<span class="badge badge-info">Normal</span>'; document.write('Content: ' + myContent.getName() + '(ID ' + mySectionContent[prop].getID() + ') ' + ' - <small>Content Type:' + myContentType.getName() + '</small> ' + myContentTypeType + '<br />'); }

The results of the above code is:

java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(java.lang.Class)] or the variable arity signatures [(java.lang.Class, java.lang.Object...)] of the method com.terminalfour.spring.ApplicationContextProvider.getBean match the argument types [jdk.dynalink.beans.StaticClass]

Get Parent Section

It is possible to retrieve the parent section of the current section to get the information. You will receive a cachedSection object that can use all the above information.

(CachedSection) mySection.getParent()Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myParentSection = mySection.getParent(); if (myParentSection !== null ) { sectionName = myParentSection.getName(language); } else { sectionName = 'Root'; } document.write('Parent Section: ' + myParentSection.getName(language) + '(ID ' + myParentSection.getID() + ')<br/>');

The results of the above code is:

Parent Section: Programmable Layouts(ID 10440)<br/>

get Grand Parent Section

It is possible get the information of the grand parent section, using the parent section information

(CachedSection) mySection.getParent().getParent();Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myParentSection = mySection.getParent(); var myGrandParentSection = myParentSection.getParent(); if (myGrandParentSection !== null ) { sectionName = myGrandParentSection.getName(language); } else { sectionName = 'Root'; } document.write('Parent Section: ' + myGrandParentSection.getName(language) + '(ID ' + myGrandParentSection.getID() + ')<br/>');

The results of the above code is:

Parent Section: Developer Resources(ID 10088)<br/>

Get all Parent Sections

Instead to get one section per time using getParent there is quickest way to get all parent section. This way you will retrieve an array of section ID.

(int[]) mySection.getPathMembers().toArray()Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myParentSections = mySection.getPathMembers().toArray(); for(prop in myParentSections) { var myParentSection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, myParentSections[prop], language); if (myParentSection !== null ) { sectionName = myParentSection.getName(language); } else { sectionName = 'Root'; } document.write('Parent Section: ' + sectionName + '(ID ' + myParentSections[prop] + ')<br/>'); }

The results of the above code is:

Parent Section: Home(ID 10078)<br/>Parent Section: Documentation(ID 10086)<br/>Parent Section: Developer Resources(ID 10088)<br/>Parent Section: Programmable Layouts(ID 10440)<br/>Parent Section: Programmable Layouts: Section Information(ID 10443)<br/>

Get SEO Key Phrases

To get the SEO Key Phrases you will need to use the following code:

Name
Type
Global Variable
Description 
language string language it is the language information (e.g. 'en')
(string) mySection.getKeyPhrase((string) language);Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myKeyPhrase = mySection.getKeyPhrase(language); document.write('SEO Keyphrases: ' + myKeyPhrase + '<br/>');

The results of the above code is:

SEO Keyphrases: <br/>

Get Page Layout of a section.

To get the page layout of section. The following method will retrieve the  ID of the page layout. 

Name
Type
Global Variable
Description 
channel Channel publishCache.getChannel() it is the channel configuration.
(integer) section.getStyle(channel);Examplevar sectionID = section.getID(); var channel = publishCache.getChannel(); var mySection = com.terminalfour.publish.utils.TreeTraversalUtils.findSection(channel, section, sectionID, language); var myPageLayoutID = section.getStyle(channel); document.write('Page Layout ID : ' + myPageLayoutID + '<br/>');

The results of the above code is:

Page Layout ID : 34356<br/>