Determining the current web content context | HCL Digital Experience
To determine the current web content context of a portal page or Web Content Viewer portlet, you can use the WCM Page Context Service. This service provides the ID of the currently rendered item of a page or portlet.
To obtain an instance of the service, you can use one
of the following home interfaces:
- PortalWcmPageContextServiceHome
- Use this home interface if the calling code has access to the
HTTPServletRequest
, for example, if the theme calls it. - PortletWcmPageContextServiceProvider
- Use this home interface if the calling code has access to a
PortletRequest
, for example, if a portlet calls it. - CorWcmPageContextServiceHome
- Use this home interface if the calling code has access to a
com.ibm.content.operations.registry.api.Context
, for example, if a resolver calls it.
WCMPageContextService
provides
the following two methods:- getWcmPageContext
- This method returns the ID of the current web content context. Depending on the parameters that you pass in, it is the context of a page or Web Content Viewer portlet. The service evaluates the following conditions in the order given here:
- Private render parameter. This condition is available only for Web Content Viewer portlets and not for pages.
path-info
parameter.- Public render parameter.
- Portlet configuration setting for the web content viewer. This condition is available only for Web Content Viewer portlets and not for pages.
- Web content association that is defined for the page.
The context can be a content item or site area. If the context is a site area, you can use the method
getWcmDefaultContent
to determine the default content of the site area. - getWcmDefaultContent
- This method returns the default content of a site area. This method is useful if the current web content context is a site area and you need to determine the content item that is actually rendered.
getPathById
of the HCL Web Content Manager workspace to transform
the ID to the corresponding content path. For more information, read
the API documentation.