ASPX templates
Version 4.x > ASPX templates > dynamic page redirect to first child node under parent node View modes: 
User avatar
Member
Member
tony - 2/25/2011 5:04:12 AM
   
dynamic page redirect to first child node under parent node
Just thought someone might find this useful. For example if you need parent node to redirect it to the first child document dynamically, just include the code in Page_load().

string parentNodeAliasPath = (string)CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeAliasPath.ToLower();
parentNodeAliasPath = parentNodeAliasPath.Trim() + "/%";

CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider();
DataSet ds = tree.SelectNodes(CMS.CMSHelper.CMSContext.CurrentSiteName, parentNodeAliasPath, CMS.CMSHelper.CMSContext.CurrentDocument.DocumentCulture, false);

if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(ds))
{
// If child nodes exist
DataView dtView = ds.Tables[0].DefaultView;
dtView.Sort = "nodeOrder ASC";
string path = dtView[0]["NodeAliasPath"].ToString();
string resolvedURL = ResolveUrl(CMSContext.GetUrl(path));
Response.Redirect(resolvedURL);
}
else
{
//If child nodes do not exist do not redirect
}

User avatar
Certified Developer 8
Certified Developer 8
dvanbale - 3/2/2011 5:49:59 AM
   
RE:dynamic page redirect to first child node under parent node
Hello Tony,

Great stuff, it's similiar to how we solve this internally, a collegue of mine made a template which does runs code like yours, so end users can decide for them selves which pages go where.

User avatar
Member
Member
theplastictoy - 8/18/2011 10:10:05 AM
   
RE:dynamic page redirect to first child node under parent node
Hi tony,

Nice one. Was implementing this myself. Thanks for sharing.

Ricardo