Website Search Feature Restored

Posted by Hans de Ruiter

I got an email this morning from someone who tried to use the search functionality of this website, and got a "Generated with the default ContentController.ss template" error. Apparently, the search function has been broken since I upgraded to Silverstripe 2.4.0, and no-one noticed (obviously, I didn't), or bothered to tell me up to now. Anyway, it is now fixed, and I have updated the Silverstripe JRank Integration page with a new archive.

There were two issues. The first is that the API of Silverstripe's XML class was changed, breaking my code in the process. However, even with this fixed, the Generated with the default ContentController.ss template" error persisted. This was despite the template being present, and even being partially executed (according to stack dumps that I deliberately triggered). This confused me for a while. Even more confusing was that it suddenly worked, albeit with a broken layout, when I changed the SearchResultsPage class to be a child-class of Page, and its controller to a child-class of Page_Controller.

Eventually, I realised that the template file was in the wrong place. Since the SearchResultsPage is a direct child-class of SiteTree, its template is supposed to be in the templates directory (where the base Page.ss is), not templates/Layout, where it had been put. For some reason having the template in the wrong place used to work pre-Silverstripe-2.4.0, but not anymore.

NOTE: I made the SearchResultsPage class a child-class of SiteTree so that I could eliminate the left-column navigation bar for the search results, which would have made the layout too cramped. If you want to use the same base layout as the rest of your pages, change the SearchResultsPage to be a child-class of Page, the SearchResultsPage_Controller to be a child-class of Page_Controller, and move SearchResultsPage.ss to templates/Layout.