Can't consistency override custom-search-result.html.twig theme template

Created on 12 June 2017, over 7 years ago
Updated 20 October 2023, about 1 year ago

Very difficult/impossible to override the template for individual search results: custom-search-result.html-twig
I'm able to override it by placing search-result--node-search.html.twig in my theme's template dir, but it only works the first time after a full cache flush. After page reload, the theme engine reverts to using the template file provided in the custom_search module: custom-search-result.html.twig

🐛 Bug report
Status

Needs work

Component

Code

Created by

🇨🇦Canada ryrye

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France aiphes

    With Custom Search (custom_search) Enabled 8.x-1.0-beta9 , suggestion disappear.
    Do I need to repatch ?

  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany guido_s Cologne

    Patch #15 doesn't apply to beta-9 and search-result.html.twig in my theme won't get used although it's the suggested file name.
    So the patch needs at least a reroll.

  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany guido_s Cologne

    I rerolled the patch from #15 and resolved merge conflicts in the rebase process which occurred in the custom_search_theme_registry_alter() function. Those conflicts were a result from replaced deprecated functions.
    So I removed the lines just like patch #15 did.

    The rerolled patch should apply to 8.x-1.0-beta9

  • 🇫🇷France aiphes

    Thanks to #19. It works for the beta9.
    Search Custom Search (custom_search) Enabled 8.x-1.0-beta9

    modules/contrib/custom_search$ curl https://www.drupal.org/files/issues/2023-04-24/custom_search-2885485-19.patch | git apply
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 18063  100 18063    0     0  42601      0 --:--:-- --:--:-- --:--:-- 42601
    
  • Status changed to Needs work about 1 year ago
  • 🇫🇷France cedric_a France

    I just tested the patch #19 on a fresh Drupal 10.1.5 with Custom Search 8.x-1.0-beta9 and I could override the template custom-search-result.html.twig by copying it from the module folder to my custom theme folder.
    However, the twig debug is showing this error message in the markup :

    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'search_result' -->
    <!-- FILE NAME SUGGESTIONS:
       * search-result--node-search.html.twig
       * search-result.html.twig
    -->
    <!-- INVALID FILE NAME SUGGESTIONS:
       See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter
       custom_search_result__node_search
       custom_search_result
    -->
    <!-- BEGIN OUTPUT from 'themes/thematik/templates/custom-search-result.html.twig' -->
    [...]
    <!-- END OUTPUT from 'themes/thematik/templates/custom-search-result.html.twig' -->
    

    So I looked at the api doc mentionned and spoted this :

    New suggestions must begin with the value of HOOK, followed by two underscores to be discoverable.

    I tested to change the suggestions from "custom_search_result__" to "search_result__", it removes the warning and show the template used with an "x".
    But I think that it's not the suggestion name that we want because it is the name of the core search result template.
    Should we adopt a suggestion name like "search_result__custom_search__" ?
    I'm wondering if these changes will break backward compatibility too.

Production build 0.71.5 2024