1
  • Hello im using Drupal 9.5.9 version. How can I add the hero section image in the View to REST_API?

  • I have created an api with Rest_API to fetch data from Views I have created. I have no problem retrieving public data. However, I am getting "null"/"empty"/"id" errors when trying to get the image in the Hero Section in the View. I created two paths to get the images in the view, one to get all the views in the same category (jsonapi/news/) and the other to list the view whose id I entered (jsonapi/news/2775).

  • After adding Hero section from the Fields section in the View to get the image, I tried to get the img tags by making Rewrite results > Strip HTML tags to get the image link properly, but I'm still having problems.

    • When I list all views in the same category (jsonapi/news) enter image description here
    • When I list a single view (jsonapi/news/id)enter image description here
    • When I list a single view (jsonapi/news/id) with strip img tagsenter image description here
    • Another method I tried is Rewrite Results > Override the output of this field with custom text {% if field_hero_section %} <img src="{{ file_url(field_hero_section.entity.field_image.entity) }}" /> {% endif % } I filtered by trying this code, but the result I got is; enter image description here

How can i solve this ? Which method i should use ?

0

Your Answer

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

Browse other questions tagged or ask your own question.