Gravatar for

Question by jschjolberg, Jul 7, 2014 11:56 AM

Can you add language to the query when using the JavaScript Framework?

We're using the JavaScript Framework w/ Sitecore. I'd like to pass a language code into the query. Is this possible?

Gravatar for

Comment by Martin Laporte, Jul 7, 2014 11:58 AM

I'm not sure I understand your intent --- do you want to filter only items in a specific language? Or something else?

1 Reply
Gravatar for

Answer by Vincent Séguin, Jul 7, 2014 12:13 PM


Do you want to query directly on the language? OOTB, there's a filter on the current language that is traducted in something like (@flanguage85698=="en").

You could add your own query on the field Language by using the ToCoveoFieldName extension. So for example, in your layout file, you could add something like this:

Coveo.$('#search').on('buildingQuery', function(e, args) {
    args.queryBuilder.advancedExpression.add('<%= ToCoveoFieldName("Language") %> == "myLanguageCode"');

If you don't want the default filter on the current language, you could remove it this way (i assume you're on the June build or higher) :

Coveo.$(function() {
    var options = <%= Model.GetJavaScriptInitializationOptions() %>;
    options.filterResultsOnCurrentCulture = false;
    Coveo.$('#search').coveoForSitecore('init', options);
Ask a question