2
votes

I am experiencing the following error when trying to display an image gallery Advanced Custom Field's field on my client's website.

Fatal error: Uncaught Exception: Unknown "get_image" function.

I have tried switching the image galleries return format between array, URL, and ID, but the same issue always occurs.

The code that I am using to display the gallery of images is being used in a category Twig file using the following code. Not all story posts have galleries, but the if statement should be handling this I assume.

I copied the gallery output code directly from the Timber documentation site.

Timber is up to date using 1.18.2.

{% if story.meta( 'photo_gallery' ) %}
  {% for image in story.meta( 'photo_gallery' ) %}
  <img src="{{ get_image(image) }}" />
  {% endfor %}
{% endif %}
3

3 Answers

1
votes

That’s actually an error in the documentation. The get_image() function is a function from the upcoming 2 version of Timber, but shouldn’t be listed in the documentation for version 1.

It should work if you use Image() instead of get_image():

{% if story.meta( 'photo_gallery' ) %}
  {% for image in story.meta( 'photo_gallery' ) %}
      <img src="{{ Image(image) }}" />
  {% endfor %}
{% endif %}

I’ll check if I can get the documentation fixed.

Update – This is now fixed in the documentation.

0
votes

The Advanced Custom Fields plugin does not implement a get_image function. Are you sure it shouldn't be get_field(image) instead of get_image(image)?

0
votes

If you are using ACF plugin, you can use below code to get the ACF image:

{% for item in block_content.add_services %}
    <img src="{{ item.add_service_logo.url }}" alt="{{ item.add_service_logo.alt}}" >
{% endfor %}

add_services is for the ACF repeater and add_service_logo is used for the image (return as an array).