yellowpencil: Accessing parent page information in OpenText™ WSM
A 3 minutes read, written by Jon
June 20, 2014
When you’re working with OpenText WSM Content Classes, you’ll often need to grab information from a parent page. This can range from displaying a simple value, all the way to performing logic based on the information stored in the parent page.
A page can have many homes
One of the first concepts you need to understand is that a content class can have a single instance connected in multiple locations in the site. Each page has a “Main Link” that typically represents where the page lives in the navigation structure.
Getting page information from the Main Link
Grabbing information from the Main Link is relatively easy. Grab the value of a headline with this RenderTag:
<%!! Context.CurrentPage.MainLink.OwnerPage.Headline !!%>
To get the value of a Text Field (txt_body):
<%!! Context:CurrentPage.MainLink.OwnerPage.Elements.GetElement(txt_body).GetHtml().ToString() !!%>
These tags apply to a page that lives in the navigation structure that wants to obtain information from its parent.
Getting Current Page information from within a module
But what if you have a module (a component on a page) that needs information from the page it’s attached to? Main Link won’t work in that case. Instead you need a tag that changes contextually based on its perceived location. You have one instance of the module that’s connected to many locations – the value should be unique for each location.
This is where CurrentIndex.Page comes in. On a Master Page (or Foundation Page), the code CurrentIndex.Page will represent the page itself. On a Module page (or a page that is connected to a container), CurrentIndex.Page will represent the page that the module is connected to, since the CurrentIndex.Page refers to the current page or location in Navigation.
This allows you to create a module that can be preassigned in a one-size-fits-all manner, but also create a hook into your master page to allow an override behaviour.
In this code snippet, the module will take the value “txt_parentvalue” from the parent if it exists. Otherwise it will render the default “myvalue”.
<%!! Context:CurrentIndex.Page.Elements.GetElement(txt_parentvalue).GetHtml().ToString() !!%>
This technique gives you even more flexibility with OpenText WSM. Happy coding!
Source: Accessing parent page information in OpenText WSM
© copyright 2014 by yellowpencil