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:
- Went to
/admin/structure/types/manage/product/display
(Structure > Content Types > Product > Manage Display)
. Turned onSearch Index
andSearch result highlight input
.
- Navigated to
Search result highlight input
tab and added (enabled) two fields Product summary and Product price
- Went back to search result but I still cannot see the those variables in rendered array.
Can somebody please tell me the best way to accomplish the above?