Page Title
Is there a way to dinamically change the pages title at runtime?
I know that you can change the page title at the portal level, but this solution
doesn’t offer any SEO value since it doesn’t change the TITLE tag in the page.
For what I’ve seen the way to changing the portal titles are very static (these are global settings):
- Changing the bannerTitleText in the theme policy
- If that’s not present adjust the bannerTitleTextResourceBundle and bannerTitleTextResourceKey to the desired value.
- Otherwise, set the titles globally at the theme configuration
Our goal is to be able to set the title at the page level so that it can change from page to page and include the relevant page’s keyword.
Actually it would be most ideal if this could be done from WCM.
Update
I noticed that the default theme in WebSphere Portal 6.1.5 was appending the page title, so examined the theme and surely enough the jspInit.jspf had some the following new methods:
private static com.ibm.portal.state.service.PortalStateManagerServiceHome portalStateManagerServiceHome;
// (This goes in the jspInit constructor)
portalStateManagerServiceHome = (com.ibm.portal.state.service.PortalStateManagerServiceHome) ctx.lookup("portal:service/state/PortalStateManager");
protected com.ibm.portal.state.service.PortalStateManagerService getStateManagerService( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws Exception {
final com.ibm.portal.state.service.PortalStateManagerService psms = portalStateManagerServiceHome.getPortalStateManagerService( (javax.servlet.http.HttpServletRequest) request, (javax.servlet.http.HttpServletResponse) response );
return psms;
}
protected boolean isStaticPage( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
final com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
final com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
final com.ibm.portal.navigation.NavigationNode currentNavNode = (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
final com.ibm.portal.content.ContentNode currentContentNode = currentNavNode.getContentNode();
return currentContentNode.getContentNodeType().equals( com.ibm.portal.content.ContentNodeType.STATICPAGE );
}
protected com.ibm.portal.navigation.NavigationNode getSelectedNode( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
return (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
}
protected String getSelectedNodeTitle( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
final String title;
if ( localizedContextHome != null ) {
com.ibm.portal.model.LocalizedContext context = localizedContextHome.getLocalizedContext( (javax.servlet.http.HttpServletRequest) request );
title = context.getTitle( getSelectedNode( request, response ) );
} else {
title = "";
}
return title;
}
After adding this I was able to copy the head_title.jspf from the 6.1.5 theme; which includes the following new lines:
<c:set var="selectedNodeTitle" value="<%=getSelectedNodeTitle(request, response)%>" />
<title><c:out value="${siteTitle} - ${selectedNodeTitle}"/></title>
Now all that’s left is figuring out a way of fetching this from WCM.
I just wanted to update this question to mention that there’s a new feature that enables a better way to achieve this same goal.
The new Web Content Viewer (286) takes advantage of a new feature in the JSR 286 called two phase rendering in which a new event is created called doHeaders. Under the doHeaders event the response can be modified in order to add elements in the head such as title.
Now the Web Content Viewer provides a Page Display Title setting which enables you to do a Select from content.
Now all that’s left really is to enable us developers set other elements from Web Content such as: Canonical elements/links, meta tags, etc. But I think that the new Web Content Folders feature can enable us to build something at the theme level.
Good luck to every SEO conscious Lotus Web Content Management developers out there.