Rendering
Content templates consist of two elements:
- Renderers (Apex class)
- Content Edit Page (Visualforce Page)
The typical framework of an Apex class used for rendering OrchestraCMS content contains:
- The HTML markup that will be output on the website for content in a template fashion
- The accessors that retrieve the values of the attributes entered by content authors for a specific instance of content using the template
- Any Apex logic (e.g. if conditions, loops, SOQL, SOSL, callouts, etc.)
Below is an example of a basic content renderer.
global virtual with sharing class SampleContentTemplate extends cms.ContentTemplateController {
global SampleContentTemplate(cms.CreateContentController cc) {
super(cc);
}
global SampleContentTemplate() {}
public String myAttr {
get {
return(this.getProperty('myAttr'));
}
}
global virtual override String getHTML() {
String html = '';
html += '<div class="myClass">' + myAttr + '</div>';
return html;
}
}
A content renderer will typically extend cms.ContentTemplateContoller. It also needs a constructor that can be used within the Visualforce page that will act as the content editor page. Accessors are also required to retrieve each of the attributes entered in by the content author when they created the content. Finally, it needs to override the global getHTML method and return the provided markup.