Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Child Page accessing Parent Page Custom Properties View modes: 
User avatar
Member
Member
adegiamb - 4/29/2009 2:11:36 PM
   
Child Page accessing Parent Page Custom Properties
Let’s say we have the following page structure


Main - (contains configuration properties)
-Sub 1
-Item 11
-Item 12
-Item 13
-Sub 2
-Item 21
-Item 22
-Item 23


The main page has configuration properties that each item pages will need to use. How would you get the Item Page to read the properties from the Main page?

The way I got it to work but not sure is the best way is I get the current node and loop through the parent node until I find a node with the NodeClassName = “custom.config”.

Does anyone know of a better way of doing this?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/12/2009 8:15:08 AM
   
RE:Child Page accessing Parent Page Custom Properties
Hi,

If you are using something like this:
CMS.TreeEngine.TreeProvider tp = new TreeProvider();
CMS.TreeEngine.TreeNode currentNode = tp.SelectSingleNode(CMS.CMSHelper.CMSContext.CurrentSiteName, CMS.CMSHelper.CMSContext.CurrentAliasPath, CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentCulture);
while(currentNode.NodeParentID != null)
{
if(currentNode.ClassName == "Custom.config")
break;
else
currentNode = tp.SelectSingleNode(currentNode.NodeParentID);
}


It is also correct way. You can also get the parent document using this, which is very similar:
CMS.TreeEngine.TreeProvider tp = new TreeProvider();
CMS.TreeEngine.TreeNode currentNode = tp.SelectSingleNode(CMS.CMSHelper.CMSContext.CurrentSiteName, CMS.CMSHelper.CMSContext.CurrentAliasPath, CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentCulture);
CMS.TreeEngine.TreeNode parentNode = tp.SelectSingleNode(currentNode.NodeParentID);
string documentName = parentNode.DocumentName;


Best Regards,
Juraj Ondrus