Reputation: 3064
I have a custom content type with several fields like Price, Product Summary, Product image etc. Is there any way I can access these fields separately on search result page?
I printed the rendered array on mytheme/item-list.html.twig
using kint(item.value)
which shows that I can only access title
, url
and type
separately like {{ item.value['#result'].url }}
, {{ item.value['#result'].title }}
. But don't see variables like product_image
, product_summary
etc. in rendered array.
According to Twig template suggestion the template I need to override is search-result.html.twig
. So I copied /core/themes/stable/templates/content/search-result.html.twig
to my theme's folder. However, the {{ snippet }}
variable does not have information I want to access.
I went through the following steps to customise the result output:
/admin/structure/types/manage/product/display
(Structure > Content Types > Product > Manage Display)
. Turned on Search Index
and Search result highlight input
.Search result highlight input
tab and added (enabled) two fields Product summary and Product priceCan somebody please tell me the best way to accomplish the above?
Upvotes: 2
Views: 6570
Reputation: 64
@Subrata Sarkar There is one option. Firstly,install two module search_api and search_api_page module from drupal.org
https://www.drupal.org/project/search_api
https://www.drupal.org/project/search_api_page
Add server and index in search api.
Add the fields which you want to display on page within index and after all configuration indexed all your data.
After this create and configure search page.And choose view mode option and select a view mode ex: Search result highlighting input or Search index etc.
Hope you get your desired result on search page.For more information, https://www.youtube.com/watch?v=dNilEVQu94I
Upvotes: 1