Blog » Website Search Feature Restored

Website Search Feature Restored

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 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 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 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 to templates/Layout.

Blog » Website Search Feature Restored

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments

Blog » Website Search Feature Restored