• Client login
  • Work for us

All the latest from the team...

Tuesday, 12 February 2008

DNN - Returning Page titles in place of Module titles for Search Results

Those of you using DotNetNuke (DNN) as the platform for your site build have probably encountered the problem where that DNN displays the module name in the search results and NOT the page name.

There is a pretty simple fix to this. In SearchResults.ascx.vb (located in admin->search) simply add the public function "FormatTitle" as per below:

Public Function FormatTitle(ByVal TabID As Integer) As String

Dim strURL As String

Dim objTabs As New DotNetNuke.Entities.Tabs.TabController
Dim objTab As DotNetNuke.Entities.Tabs.TabInfo

objTab = objTabs.GetTab(TabID)

strURL = objTab.Title.ToString()
If strURL = "" Then
strURL = "Home"
End If

Return strURL
End Function


This will get the page name from the TabID returned from the stored procedure GetSearchResults.

Next, to display the page name, add the following line to SearchResults.ascx:

<asp:HyperLink id="pageTitle" runat="server" CssClass="SubHead" NavigateUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem,"TabId"),DataBinder.Eval(Container.DataItem,"Guid")) %>' Text='<%# FormatTitle(DataBinder.Eval(Container.DataItem,"TabId")) %>'></asp:HyperLink>

And you should now see the page name in your results set instead of the module name!

Labels: , , , , ,

RSS feed ATOM feed Add to Technorati Favorites View Jon Harvey's profile on LinkedIn