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):

<script>
  (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:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>

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. http://example.org/dokuwiki/search).

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:

<gcse:searchresults-only></gcse:searchresults-only>

Now you can trigger search results on this page by passing a q argument in the url:

http://example.org/dokuwiki/search?q=myQuery
If you use the <html> tag, enable the config:htmlok option.
  • tips/google-cse.txt
  • Last modified: 8 years ago
  • (external edit)