Coveo for Sitecore 5 is now available!

Adding Custom Parameters by Creating a New Template Using the Coveo for Sitecore Legacy Search UI Framework

Coveo for Sitecore 4.1 (November 2018)

As explained in Adding Custom Parameters with the Additional Parameters Field, you can easily add custom parameters with the Additional Parameters field. However, this has a few drawbacks:

  • It requires the content author to know the exact name of the parameter.
  • The parameter value is inserted as a single-line text field, which is not necessarily appropriate for every type of content. For example, in the case of the boolean flag isVisible, a check box would be easier to modify than a single-line text field, as the content author would simply have to select or unselect it instead of writing true or false.

This tutorial demonstrates how to create your own parameter templates in order to specify custom parameters and make it easier for the content authors to modify their values.

Steps

  1. Open the Sitecore Content Editor.
  2. Right click on the User Defined template folder (typically located under /sitecore/Templates/User Defined).
  3. Choose Insert > New Template.

  4. In the next dialog, enter the following values:
    1. Name: Custom Search Parameters (or any other name).
    2. Base template: Templates/CoveoModule/Search/Coveo Search Parameters.
  5. Choose Next.

  6. Select the User Defined folder for the location and choose Next.

  7. Add a new section named Layout to the template.

  8. Add a new Checkbox field named DisplayResultsUri.

  9. Save your template.
  10. Locate the Coveo Search sublayout in the content tree (typically located under/sitecore/Layout/Sublayouts/Coveo/Coveo Search).
  11. Replace the Parameters Template field value with the template that you have already created previously (i.e., Custom Search Parameters).

  12. Save your template.
  13. Select your search page in the content tree and access its Layout Details (Presentation > Details).
  14. Edit the list of controls associated with the Default device by clicking on the Edit button.
  15. In the Device Editor dialog, select Controls in the left-hand side panel.
  16. In the right-hand side panel, select the Coveo Search component and click Edit.

  17. Locate the DisplayResultsUri parameter that you added previously and clear its checkbox.

  18. Open your Coveo Search Component sublayout in a text editor (typically located under Website/layouts/Coveo/CoveoSearch.ascx).
  19. Add the following script block in order to use the DisplayResultsUri parameter in your sublayout.

    <script runat="server">
    public bool DisplayResultsUri
    {
        get {
            return GetBoolParam("DisplayResultsUri");
        }
    }
    </script>
    

    The CoveoUserControl class defines multiple helper functions (e.g., GetBoolParam, GetIntParam, GetStringParam, etc.) to help you retrieve parameter values.

  20. Insert the following code around the div with a class equal to CoveoPrintableUri to be able to show/hide it depending on the value of the DisplayResultsUri parameter.

    {{ if (<%= DisplayResultsUri ? "true" : "false" %>) { }}
    <div class='CoveoPrintableUri'></div>
    {{ } }}
    
  21. Save the file.
  22. Open your search page in a web browser to validate that the result URIs are no longer displayed when the DisplayResultsUri parameter is cleared.