asp.net - Using SiteMapPath to create a dynamic page title? -
i use sitemappath generate breadcrumb asp.net 3.5 (vb.net) pages , works great.
now trying figure out how might able use same control build dynamic page title (in tag). want reverse path listed, sitemappath control includes links , bunch of styling spans. there way remove of that, , plain path separators?
for example, let's on "press releases" page inside of "about" section of site.
the breadcrumb shows as:
home > > press releases
i want have page title be:
press releases - - company name
so need reverse order, drop spans, links , styling (since inside tag) , drop root node "home" , add company name end. since menu nav , breadrumbs driven sitemap file, thought make sense try make title same.
any thoughts? thanks.
the best way achieve desired output ignore sitepath control, , instead use sitemap's sitemapnode's collection. server parses web.sitemap collection of sitemapnodes , wires sitemap.currentnode finding node matches current page's url. each sitemapnode has parentnode property. here reference page on msdn.
so, need check if currentnode has parent, if add parentnode's title currentnode's title , keep going until reach rootnode (where substitute company name root node's title).
below quick solution; go in masterpage if using one. i'm not sure language, should easy rewrite in vb.net. gave simple test , seemed work. can customize characters separate page titles.
protected void page_load(object sender, eventargs e) { page.title = sitemaptitle(sitemap.currentnode, "", " - "); } private string getnodetitle(sitemapnode onode) { if (onode == sitemap.rootnode) return "company name"; else return onode.title; } private string sitemaptitle(sitemapnode onode, string sztitle, string szitemseparator) { if (sztitle != string.empty) sztitle = sztitle + szitemseparator + getnodetitle(onode); else sztitle = getnodetitle(onode); if (onode.parentnode != null) sztitle = sitemaptitle(onode.parentnode, sztitle, szitemseparator); return sztitle; }
hope helps...
Comments
Post a Comment