OrchestraCMS Custom Content Types that Include User Info

OrchestraCMS is a powerful content management system that resides directly on the Salesforce platform.  This allows us to leverage data that’s stored within Salesforce, giving us the ability to leverage an authenticated user’s data to fully customize their experience.  Using a custom content type in OrchestraCMS, we can take that a step further, allowing non-technical CMS content editors to have access to choose how that information is displayed on the live site.

In the example below I’ve created a custom field on the users record in Salesforce called Favorite Color.  It’s a picklist with three options, red, green, and blue.  I’ve also created an OrchestraCMS edit page for this custom content type and given it three fields for the different text that should be displayed depending on what the user’s record contains for Favorite Color.  In the example I’ve used HTML text, but these could be any type including text area and WYSIWYG content.

With the basic setup complete, the next thing is to determine which field gets displayed based on the user’s information.  This is handled in the controller, and in this example I’m using the getFavoriteColor() method to select the content to render depending on the value of the authenticated user’s Favorite Color field.  The controller gets the value of that picklist, then returns the text that was saved for that content type in OrchstraCMS.  Here is a look at the code.

Example Controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
global with sharing class ExampleContentController extends cms.ContentTemplateController {
    
    global ExampleContentController(cms.GenerateContent gc) {
        super(gc);
    }
    global ExampleContentController(cms.CreateContentController ccc) {
        this.content =  ccc.content;
        this.content_properties = ccc.content_properties;
    }
    
    public String getFavoriteColor() {
        User u = [SELECT Id, UserName, Favorite_Color__c FROM User WHERE Id =: UserInfo.getUserId()];
        return this.getProperty(u.Favorite_Color__c);
    }
  public String getBlue() {
        return this.getProperty('Blue');
    }
    
    public String getRed() {
        return this.getProperty('Red');
    }
    
    public String getGreen() {
        return this.getProperty('Green');
    }
}

Example Display Template

1
2
3
4
5
6
7
8
9
10
11
12
<apex:page controller="cms.GenerateContent" extensions="ExampleContentController">
    
        
        
            {:Start:}
                <h1>Users Filtered Content Based on Color Is: <apex:outputtext value="{!FavoriteColor}"></apex:outputtext></h1>
<p>            {:Stop:}<br>
        </p>
<p>    </p>
</apex:page>

Example Edit Template

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<apex:page controller="cms.CreateContentController" extensions="ExampleContentController">
    <script type="text/javascript">
        function saveLookAndFeel(cb) {
            var attributes = new Array();
            attributes.push({"name":"Red", "value":$('#Red').val(), "type":"Text"});
            attributes.push({"name":"Green", "value":$('#Green').val(), "type":"Text"});
            attributes.push({"name":"Blue", "value":$('#Blue').val(), "type":"Text"});           
            $.ocms.saveContent({"name":"{!JSENCODE(content.cms__Name__c)}","content_id":"{!content.Id}","content_type":"{!content.cms__Content_Type__r.cms__Name__c}","parent_id":null},
                attributes,
                "{!JSENCODE(Content.cms__Site_Name__c)}",
                cb,
                '{!token}'
            );
        }
        function saveLookAndFeelClose(cb) {
            saveLookAndFeel(cb);
            closeTab('{!JSENCODE(tab)}');
        
    </script>
<p>    <br>
    </p><form>
<p>        </p><table>
            <tbody><tr>
              <td colspan="2">Blue Content</td><td><input value="{!Blue}" name="Blue" id="Blue" type="text"></td>
            </tr>
            <tr>
              <td colspan="2">Red Content</td><td><input value="{!Red}" name="Red" id="Red" type="text"></td>
            </tr>
            <tr>
              <td colspan="2">Green Content</td><td><input value="{!Green}" name="Green" id="Green" type="text"></td>
            </tr>
        </tbody></table><p>   <br>
    </p>
</form>
<p> </p>
</apex:page>

Final Thoughts

The example above using color is relatively simple but the same principles can be used for more elaborate requirements, such as filtering content based on language.

This entry was posted in Technology and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>