Gravatar for jhaun@singlestoneconsulting.com

Question by jhaun, Nov 11, 2016 11:00 AM

Search box view rendering parameters inheritance

Hi,

We're trying to figure out the best way to include a search box view on every page within a Sitecore website while ensuring that any changes that we make to rules or boosting will propogate appropriately.

Here's the scenario that we have:

  • A base template (call it Template A) that includes a search box view rendering in the shared layout of its standard values
  • Another template (call it Template B) that has Template A as a base template. Template B includes an additional rendering in the shared layout of its standard values

What we're experiencing is that if we change the rules in the standard values of Template A, the change does not propogate to Template B. If we reset Template B's presentation details, the changes will now show up, but the additional rendering that Template B had before (that Template A does not have) goes away.

So, what's the best way for us to ensure that:

  1. The search box view rendering is included on every page
  2. If we update the rules for the search box view those rules will take effect everywhere without having to reset the presentation details of templates that inherit
3 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Nov 11, 2016 11:37 AM

Hi Jeremy,

Sitecore doesn't support rendering template inheritance out of the box but there are some workarounds to that using rendering patches (see Always save standard values rendering field as a delta of its base template rendering field).

The first step for you would be to create a datasource item for your searchbox rendering parameters. Coveo support that by setting the datasource field on the control added to the presentation details.

You could use your template inheriting method described in your question to add the searchbox to a base template and let other templates inherit from it. Since the control will use a datasource item, you would change the searchbox options in the datasource item instead of through the presentation details.

Another solution would be to staticly add the searchbox to your layout, sublayout or view.

Web Forms:

<sc:Sublayout ID="something" runat="server" Path="/layouts/Coveo/CoveoSearchBox.ascx" DataSource="{your datasource item id}" />

MVC:

@Html.Sitecore().Rendering("{your rendering definition item id}", new { DataSource = "{your datasource item id}" })
Gravatar for jhansen@singlestoneconsulting.com

Comment by Jeff Hansen, Jan 24, 2017 11:16 AM

Jeff,

It seems like you're saying that we can simply swap out the rendering parameters that are unique to each rendering for a common datasource item. When I try that though, the Coveo SearchBoxModel that the default SearchBox rendering uses does not seem to process the datasource item. When I look at the code for the Coveo.UI.Mvc.Model.SearchboxModel class, I only see it reading the values from the rendering parameters, not looking to see if a datasource item has been attached. Do we need to write our own model to do that in order to accomplish what you're suggesting?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jan 24, 2017 11:48 AM

It is supported out of the box by all the components. The work is done by the ParametersHelper class which is used by the models. It first takes the rendering additional parameters, then the rendering parameters field values, then the datasource field values.

So datasource field values have priority over the rendering field values. Rendering field values have priority over the additional parameters collection values.

Gravatar for jhansen@singlestoneconsulting.com

Comment by Jeff Hansen, Jan 25, 2017 12:32 PM

Hi Jeff,

I've tried this by doing the following without success:

  1. Created a datasource item based on the Search Box Parameters template and set the search pageStep 1
  2. Blanked out the search page on the rendering itself and updated the datasource field to point to my Search Box Parameters itemStep 2AStep2B
  3. Previewed the page in edit mode and received an error message saying that the search page wasn't setStep 3
Gravatar for dberube@coveo.com

Comment by Dominic Berube, Jan 27, 2017 10:21 AM

Hi Jeff,

I tried to reproduce your issue, but I got it working on my side. I also get the error when I edit the Presentation Details, but I can still save it and the Preview works correctly.

I am using the latest release of Coveo for Sitecore 4.0 (January 2017), what version of Sitecore and Coveo for Sitecore are you using? If you still have the issue, I suggest you open a support case with Coveo.

Dom

Gravatar for jhaun@singlestoneconsulting.com

Answer by jhaun, Jan 27, 2017 3:33 PM

I was able to get this working by calling the renderings directly and passing in the datasource items, as suggested a previous response.

@Html.Sitecore().Rendering("{your rendering definition item id}", new { DataSource = "{your datasource item id}" })
Gravatar for adoprog@gmail.com

Answer by adoprog, May 17, 2017 11:08 AM

I'm seeing the same error as Jeff - "The search box must link to a search page." after switching from Trial license to Pro Cloud.

The only thing I've changed (according to source control) is a license key. Is it possible that the license type limits the configuration options? I'm trying to use the approach with placing rendering on all pages:

@Html.Sitecore().Rendering("{your rendering definition item id}", new { DataSource = "{your datasource item id}" })

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, May 17, 2017 12:14 PM

The license have no impact on this control. I suspect some IDs have changed between environments since this error happens only when the property `Search page item` (Called `SearchPageItemId`) is not set on the Searchbox.

So you should check either:

  1. The `Search page item` field is set properly directly in the rendering properties
  2. The `Search page item` field is set property on the datasource item used to render the rendering

Also validate that the link is valid. This field is a droptree which stores an ID. Maybe this item ID has changed between environments.

Gravatar for rizki.eka.satria@gmail.com

Comment by rizki.eka.satria, May 31, 2017 5:32 AM

Hi there,
I also experiencing similar issue which I got the error "The search box must link to a search page.".
Any solution for this?

Ask a question