Knowledge Base

Programmable Layouts: Content Layout Information

Last Modified:
14 Dec 2018
User Level:

Introduction

Programmable Layouts can retrieve information about the Content Layout in use or other Content Layouts.

Since Programmable Layouts are used as a type of Content Layout, it is often necessary to retrieve information about them. Here are some useful methods:

templateFormat (get Current Content Layout Object)

To retrieve information about the current Content Layout object you can use templateFormat

(TemplateFormat) templateFormat;Exampledocument.write(templateFormat);

The result of the above code is:

com.terminalfour.template.TemplateFormat@d482246e

get TemplateFormat Object

The TemplateFormat Object is used to handle a Content Layout. The first thing to do is retrieve the correct object depending on which Content Layout is required:

Name
Type
Global Variable
Description 
oSmt Statement dbStatment Necessary to handle the DB connection
nTemplateID integer   The Content Type ID that has the Content Layout
formatter stringer   The name of the Content Layout that we want to retrieve 


 

(string) publishCache.getTemplateFormatting(dbStatement, content.getContentTypeID(), formatter);Examplevar myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, content.getContentTypeID(), 'text/example'); document.write(myTemplateFormat);

The result of the above code is:

com.terminalfour.template.TemplateFormat@8ca16615

Get Content Layout ID

The following will return the Content Layout ID not the Content Type ID

The following is the method to retrieve the Content Layout ID:

(integer) myTemplateFormat.getTemplateID()Examplevar contentTypeLayout = 'text/example'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutId = myTemplateFormat.getTemplateID(); document.write('Content Layout ID: ' + myContentLayoutId);

The result of the above code is:

Content Layout ID: 272

Get Content Layout name

To retrieve the name of the Content Layout:

(string) myTemplateFormat.getType()Examplevar contentTypeLayout = 'text/example'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutName = myTemplateFormat.getType(); document.write('Content Layout Name: ' + myContentLayoutName + '<br/>'); var myContentLayoutName = templateFormat.getType(); document.write('Current Content Layout Name: ' + myContentLayoutName + '<br/>');

The result of the above code is:

Content Layout Name: text/example
Current Content Layout Name: text/kb

Get content layout code (T4 Standard Processor)

This works only when the called content layout has Content layout processor = T4 Standard Content

To output the actual Content Layout called use the following method:

(string) myTemplateFormat.getFormatting()Examplevar contentTypeLayout = 'text/example'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutCode = myTemplateFormat.getFormatting(); document.write('-- '+contentTypeLayout + ' -- <br/>'); document.write(com.terminalfour.publish.utils.BrokerUtils.processT4Tags(dbStatement, publishCache, section, content, language, isPreview, myContentLayoutCode)); var contentTypeLayout = 'text/programmable-layout'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutCode = myTemplateFormat.getFormatting(); document.write('<br/>-- '+contentTypeLayout + ' --<br/>'); document.write(com.terminalfour.publish.utils.BrokerUtils.processT4Tags(dbStatement, publishCache, section, content, language, isPreview, myContentLayoutCode));

The result of the above code is:

-- text/example -- 
Heading: Get content layout code (T4 Standard Processor)
-- text/programmable-layout --
document.write('Heading: '+content.get('Heading'));

Get Content Layout processor

As per the previous example, the above method works only when the Content Layout Process is T4 Standard Content. The below method is used to retrieve the Content Layout Process:

(string) myTemplateFormat.getProcessor().getProcessorType();Examplevar contentTypeLayout = 'text/example'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutCode = myTemplateFormat.getFormatting(); var myContentLayoutProcessorType = myTemplateFormat.getProcessor().getProcessorType(); if(String(myContentLayoutProcessorType) === 'JavaScript') { document.write(contentTypeLayout + ' is a programmable layout'); } else { document.write(contentTypeLayout + ' is a standard content layout<br/>') } var contentTypeLayout = 'text/programmable-layout'; //the content layout that you want to display var contentTypeID = content.getContentTypeID(); //Get current content type id or you can specify a number var myTemplateFormat = publishCache.getTemplateFormatting(dbStatement, contentTypeID, contentTypeLayout); var myContentLayoutCode = myTemplateFormat.getFormatting(); var myContentLayoutProcessorType = myTemplateFormat.getProcessor().getProcessorType(); if(String(myContentLayoutProcessorType) === 'JavaScript') { document.write(contentTypeLayout + ' is a programmable layout'); } else { document.write(contentTypeLayout +' is a standard content layout<br/>') }

The result of the above code is:

text/example is a standard content layout
text/programmable-layout is a standard content layout

Get Content Layout code (JavaScript Content)

This works only when the Content Layout has a Content Layout processor of T4 Standard Content

To output the actual Content Layout called you can use the following method:

(string) myTemplateFormat.getFormatting()Examplevar contentTypeLayout = 'text/example'; var sw = new java.io.StringWriter(); var t4w = new com.terminalfour.utils.T4StreamWriter(sw); new com.terminalfour.publish.ContentPublisher() .write(t4w, dbStatement, publishCache, section, content, contentTypeLayout, isPreview); output = sw.toString(); document.write('-- '+contentTypeLayout + ' -- <br/>'); document.write(output); var contentTypeLayout = 'text/programmable-layout'; //the content layout that you want to display var sw = new java.io.StringWriter(); var t4w = new com.terminalfour.utils.T4StreamWriter(sw); new com.terminalfour.publish.ContentPublisher() .write(t4w, dbStatement, publishCache, section, content, contentTypeLayout, isPreview); output = sw.toString(); document.write('<br/>-- '+contentTypeLayout + ' --<br/>'); document.write(output);

The result of the above code is:

-- text/example -- 
Heading: Get Content Layout code (JavaScript Content)
-- text/programmable-layout --
Heading: Get Content Layout code (JavaScript Content)