In ASP.Net, I usually control my main navigation with a standard file web.sitemap, for example:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/index.html" title="My Awesome Site">
<siteMapNode url="~/About/index.html" title="About">
<siteMapNode url="~/About/Board.html" title="Board"/>
<siteMapNode url="~/About/Vision.html" title="Vision"/>
<siteMapNode url="~/About/Mission.html" title="Mission"/>
<siteMapNode url="~/About/Support.html" title="Support"/>
<siteMapNode url="~/About/Locations.html" title="Locations"/>
<siteMapNode url="~/About/Funding-Sources.html" title="Funding Sources"/>
<siteMapNode url="~/About/Volunteer.html" title="Volunteer"/>
<siteMapNode url="~/About/Staff.html" title="Staff"/>
</siteMapNode>
<siteMapNode url="~/Parents/index.html" title="Parents">
<siteMapNode url="~/Parents/Child-Development.html" title="Child Development"/>
<siteMapNode url="~/Parents/Referrals.html" title="Referrals"/>
</siteMapNode>
<siteMapNode url="~/Resources/index.html" title="Resources">
<siteMapNode url="~/Resources/Resource-Library.html" title="Resource Library"/>
<siteMapNode url="~/Resources/Links.html" title="Links"/>
</siteMapNode>
</siteMapNode>
</siteMap>
Then I usually create a custom navigation control where I can use SiteMap.CurrentNodeand / or SiteMap.CurrentNode.IsDescendantOfto mark the current page as “selected” or whatever. I am looking for something similar for PHP. In ASP classic, we would pretty often use include and a bunch of statements ifthat work, but as soon as you get a couple of levels in depth, you get a bunch of code. I could probably create variables at the top of each page to indicate which “sections”, “unit” and “page” we are in, but I would like to avoid this if possible.
, , .
- web.sitemap, , .
EDIT - @BrandonS
, , - , . ASP.Net XML , , . , ASP.Net, , .
ASP.Net, sitemap above, ( include), <title> . My Awesome Site, L2 My Awesome Site - About L3 My Awesome Site - About - Board. . ( , , .)
ASP.Net SiteMap. ( , , , .) SiteMap.CurrentNode , Sitemap. ( Sitemap, null.) SiteMap.CurrentNode.ParentNode SiteMap.CurrentNode.ChildNodes. SiteMap.RootNode, Sitemap. SiteMap.RootNode.ChildNodes, , 2 . , , "" L3 ..
, , , node, , . , , SiteMap.CurrentNode . VB.Net , L2:
''//An array that we append potential CSS class names to such as "first" or "active"
Dim Classes As List(Of String)
''//A StringBuild is just an efficient way to work with Strings
''//if you are not familiar with it just now that Append() is basically "&=" and AppenLine() is basically "&= ...\n"
Dim Buf As New StringBuilder()
Buf.AppendLine(" <ul>")
''//Walk the root child nodes, the N variable will be the current ChildNode of the SiteMap.RootNote
For Each N As SiteMapNode In SiteMap.RootNode.ChildNodes
''//For the first and last child we want to add extra classes in case we need to adjust borders, padding, etc
Classes = New List(Of String)
If N.PreviousSibling Is Nothing Then
Classes.Add("first")
ElseIf N.NextSibling Is Nothing Then
Classes.Add("last")
End If
''//See if the page being requested is the current child or if the current page is descended from it so that we can mark it as active
If SiteMap.CurrentNode IsNot Nothing Then
If SiteMap.CurrentNode.Equals(N) OrElse SiteMap.CurrentNode.IsDescendantOf(N) Then
Classes.Add("active")
End If
End If
''//This code below is just for outputting the <li class="..."><a href="...">...</a></li> code
''//Write the opening list tag
Buf.Append(" <li")
''//If the above code created any CSS classes append the class attribute and the space-delimited list of classes
If Classes.Count > 0 Then
Buf.Append(" class=""" & Join(Classes.ToArray(), " ") & """")
End If
''//Close the list tag
Buf.Append(">")
''//Append the hyperlink. The "N" object is the current child of the SiteMap.RootNode.ChildNodes
''//All SiteMapNode objects have a Url property and a Title property which is defined in the XML file
Buf.AppendFormat("<a href=""{0}"">{1}</a></li>", N.Url.Replace("/index.html", "/"), HttpUtility.HtmlEncode(N.Title))
''//Append a blank line, I like to keep my code formatted nicely
Buf.AppendLine()
Next
''//Append the closing list tag
Buf.AppendLine(" </ul>")
, , .Net, , - PHP. , , , , .