Saturday, February 8, 2014

Special characters appearing in content presenter text. [Providing default style for content]

We use content presenter to show content from UCM. Content definition is defined by region-definition file and its template is create in webcenter. Let say we want to show news items in webcenter page.
First we define our news item. It may consist a title, a description and an image. All this definition goes in region definition file say NEWS_REG_DEF

In our webcenter content presenter template we refer region defintion and its element to show content. For example to show title of a news we use
 <af:outputText value="#{node.propertyMap['NEWS_REG_DEF:TXT_ELEMENT'].asTextHtml}"
                                                               id="ot11"/>


BUT there is a problem with this. If user has some special characters like quotes in text_element element, it will start showing &quote in UI. To avoid that we can use escape="false".
 <af:outputText value="#{node.propertyMap['NEWS_REG_DEF:TXT_ELEMENT'].asTextHtml}"
                                                               id="ot11" escape="false"/>


Now special characters will not appear in UI.

BUT at times we want to show text element with some specific styling. Using escape false, system will ignore any styleclass mentioned with outputtext.

As a solution we can create a panelgrouplayout around outputtext and specify styles on panelgrouplayout.

For example

Template code:
  <af:panelGroupLayout id="pgl21"  layout="vertical" styleClass="headline">
       <af:outputText value="#{node.propertyMap['NEWS_REG_DEF:TXT_ELEMENT'].asTextHtml}"
                  id="ot11" escape="false"/>
      </af:panelGroupLayout>


CSS:
.headline {
    font-size: 16px;
    color: #000000;
    font-weight:bold;
    }


NOTE: PanelGroupLayout can only provide default styles. If element is of type wysiwyg, contributor can put styling while creating content and in that case those styling will take preference. Functionally and Technically it makes sense also. That is why I referred it as a default syling by panelgrouplayout. It will only work if contributor has not overridden it by providing his own setting.

Disclaimer: Any views or opinions presented in this blog are solely those of the author and do not necessarily represent those of the company.

No comments:

Post a Comment