Programmable Layouts: Section Information
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.
The result 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: 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: 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:3.0:0:1566320119000:279:0 app: Get All Content from a section including system content types:3.0:0:1566320119000:279: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') |
The result 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: 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: 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:3.0:0:1566320119000:279:0 app: Get All Content from a section including system content types:3.0:0:1566320119000:279: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 result of the above code is:
Section ID: 10443
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') |
The result of the above code is:
Section name: Programmable Layouts: Section Information
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. |
The result of the above code is:
Section level: 5
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 |
The result of the above code is:
Section Path: /documentation/developer-resources/programmable-layouts/programmable-layouts-section-information/
Section Published Path: /documentation/developer-resources/programmable-layouts/programmable-layouts-section-information/
Section Preview Path: https://websites.terminalfour.com/terminalfour/preview/38/en/10443
Get Section System Directory
To retrieve the system directory of a Section used to create a link you can use the following function. publishCach
e and language
are global variables. Instead, mySection
is the cachedSection
The result 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 |
The result of the above code is:
Content: Programmable Layouts: Section Information(ID 37409) - Content Type:Documentation V8 Normal
Content: section(ID 37412) - Content Type:Programmable Layout Example Code Normal
Content: get CachedSection(ID 37410) - Content Type:Programmable Layout Example Code Normal
Content: Get Section ID(ID 37413) - Content Type:Programmable Layout Example Code Normal
Content: Get Section Name(ID 37414) - Content Type:Programmable Layout Example Code Normal
Content: Get Section Level(ID 37415) - Content Type:Programmable Layout Example Code Normal
Content: get Section Path (URL link)(ID 37416) - Content Type:Programmable Layout Example Code Normal
Content: Get Section System Directory(ID 37417) - Content Type:Programmable Layout Example Code Normal
Content: Get All Content from a Section excluding system Content Types(ID 37419) - Content Type:Programmable Layout Example Code Normal
Content: Get All Content from a section including system content types(ID 37420) - Content Type:Programmable Layout Example Code Normal
Content: Get Parent Section(ID 37421) - Content Type:Programmable Layout Example Code Normal
Content: get Grand Parent Section(ID 37422) - Content Type:Programmable Layout Example Code Normal
Content: Get all Parent Sections(ID 37423) - Content Type:Programmable Layout Example Code Normal
Content: Get SEO Key Phrases(ID 37424) - Content Type:Programmable Layout Example Code Normal
Content: Get Page Layout of a section(ID 37425) - Content Type:Programmable Layout Example Code Normal
Content: Related Links(ID 37686) - Content Type:KB Related Links Normal
Get All Content from a section including system content types
To get a list of Content Items in a Section without exclusions use the following method:
Name
|
Type
|
Global Variable
|
Description
|
---|---|---|---|
channel | Channel | publishCache.getChannel() |
Channel configuration. |
language | string | language |
Language information (e.g. 'en') |
mode | integer | See Content Mode | |
fIncludeFutureContent | boolean | false |
If false, future content will be excluded. This will take the information |
The result of the above code is:
Content: Programmable Layouts: Section Information(ID 37409) - Content Type:Documentation V8 Normal
Content: section(ID 37412) - Content Type:Programmable Layout Example Code Normal
Content: get CachedSection(ID 37410) - Content Type:Programmable Layout Example Code Normal
Content: Get Section ID(ID 37413) - Content Type:Programmable Layout Example Code Normal
Content: Get Section Name(ID 37414) - Content Type:Programmable Layout Example Code Normal
Content: Get Section Level(ID 37415) - Content Type:Programmable Layout Example Code Normal
Content: get Section Path (URL link)(ID 37416) - Content Type:Programmable Layout Example Code Normal
Content: Get Section System Directory(ID 37417) - Content Type:Programmable Layout Example Code Normal
Content: Get All Content from a Section excluding system Content Types(ID 37419) - Content Type:Programmable Layout Example Code Normal
Content: Get All Content from a section including system content types(ID 37420) - Content Type:Programmable Layout Example Code Normal
Content: Get Parent Section(ID 37421) - Content Type:Programmable Layout Example Code Normal
Content: get Grand Parent Section(ID 37422) - Content Type:Programmable Layout Example Code Normal
Content: Get all Parent Sections(ID 37423) - Content Type:Programmable Layout Example Code Normal
Content: Get SEO Key Phrases(ID 37424) - Content Type:Programmable Layout Example Code Normal
Content: Get Page Layout of a section(ID 37425) - Content Type:Programmable Layout Example Code Normal
Content: Programmable Layouts: Section Information(ID 37432) - Content Type:Section Meta Description System
Content: Related Links(ID 37686) - Content Type:KB Related Links Normal
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 result of the above code is:
Parent Section: Programmable Layouts(ID 10440)
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 result of the above code is:
Parent Section: Developer Resources(ID 10088)
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 result of the above code is:
Parent Section: Home(ID 10078)
Parent Section: Documentation(ID 10086)
Parent Section: Developer Resources(ID 10088)
Parent Section: Programmable Layouts(ID 10440)
Parent Section: Programmable Layouts: Section Information(ID 10443)
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') |
The result of the above code is:
SEO Keyphrases:
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. |
The result of the above code is:
Page Layout ID : 34356