DokuWiki and Google CSE with a stand-alone search result page

Integrate the Google CSE (Custom Search Engine) in your DokuWiki installation with a stand-alone search result page (adapted from Google CSE - Implementing search box).

Copy and paste this code in your meta.html hook present in your template directory (<dokuwiki>/tpl/<template>/meta.html):

  (function() {
    var cx = 'YOUR_ENGINE_ID';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);

Select and save the two-page layout in the Google CSE Control Panel. On one page, implement a stand-alone search box, changing the resultsUrl attribute to point to the url where you want to display the results (eg.

Copy and paste this code in the sidebar (or in one of many hooks or in your preferred location):

<gcse:searchbox-only resultsUrl="YOUR_RESULTS_PAGE_URL"></gcse:searchbox-only>

To implement a stand-alone search results page, create a new DokuWiki page (eg. search) and paste the results code snippet into your results page:


Now you can trigger search results on this page by passing a q argument in the url:
If you use the <html> tag, enable the config:htmlok option.
  • tips/google-cse.txt
  • Last modified: 8 years ago
  • (external edit)