Previous Page Element
The previous post discussed pulling in the "headline" of a previous (parent) page. But what if you want to pull in another element?
OpenText allows you to pull in the following page's element, however it does not provide the same feature for pulling in information from a parent page. Enter render tags.
In this example, my element is named "stf_moreinfo". This is text on the navigation items for each subsection of the website. I am allowing the editors to determine this text field for their section. As they create pages within their section, this field will automatically populate with the text put on their homepage so that they only need to enter the data once.
<%!!Context:CurrentPage.MainLink.OwnerPage.Elements.GetElement(stf_moreinfo).GetHtml()!!>
But then I ran into the problem when editors started creating grandchild pages. The script above goes one layer deep and does not touch the second level. This was solved by doubling up on the elements.
<%!!Context:CurrentPage.MainLink.OwnerPage.MainLink.OwnerPage.Elements.GetElement(stf_moreinfo).GetHtml()!!%>
I limit the number of levels to 4, and to accomadate these levels I have a dirty bit of replicating code that could probably be more elegant given a counter statement embedded in the navigation, but for now this solution gets the element to post whether the template is embedded on level 2 or level 4.
<%!!Context:CurrentPage.MainLink.OwnerPage.Elements.GetElement(stf_moreinfo).GetHtml()!!%>
<%!!Context:CurrentPage.MainLink.OwnerPage.MainLink.OwnerPage.Elements.GetElement(stf_moreinfo).GetHtml()!!%>
<%!!Context:CurrentPage.MainLink.OwnerPage.MainLink.OwnerPage.MainLink.OwnerPage.Elements.GetElement(stf_moreinfo).GetHtml()!!%>
Basically I layered three levels with the GetHtml tag. It says:
"if your parent page has a value for stf_moreinfo then display that info, if not go to next bit of code."
"if above is false then search parent page's parent and display that value"
"if above is false search parent page's parent page's parent element and display that value"
else just skip.
No comments below.
Add your thoughts