In SXA Sitecore 93 I have a requirement to show items in search result, where date field on page is only greater than current date.

I am trying to create a custom sxa token just like we have: ItemsWithTheSameValueInField | FieldName, where I am going to put the logic of filtering the model with past date for the given fieldName.

Is this approach is fine or do anyone have better option to full fill the requirement.?

Thanks in advance.

1 Answer 1


That approach is fine.

You can create your token that can check on dates and use the current date. If you pass the date field name as a parameter you could reuse it as well. If you need some guidance on how to write this, I have blog post explaining that exactly: https://ggullentops.blogspot.com/2019/01/extending-sxa-search-query-tokens.html

In short, you need to write a processor for the ResolveSearchQueryTokens pipeline:

  • loops over the SearchStringModels to find you token
  • build a new SearchStringModel that contains your logic (using the field from your parameters and the current date)

Building that model could look like this:

protected virtual SearchStringModel BuildModel(string fieldName, string fieldValue)
  var name = SomeBusinessLogicWithFieldName(fieldName);
  var value = SomeBusinessLogicWithFieldValue(fieldValue);
  return new SearchStringModel("custom", FormattableString.Invariant(FormattableStringFactory.Create("{0}|{1}", name, value)))
    Operation = "must"
  • Thanks @gatogordo, I have being following your blog for guidelines, thanks for prompt reply , i'll update you if it works out.
    – Tabbuu
    Nov 20, 2020 at 9:44
  • One problem I'm facing is , i cant see suggestion of new token while creating query, and it the patch is making every other search result null.
    – Tabbuu
    Nov 20, 2020 at 10:59
  • I think you have a bug... maybe create another question and include all you did
    – Gatogordo
    Nov 20, 2020 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.