简体   繁体   English

Output 图片来自 ACF 选项字段

[英]Output Image from ACF options field

How can I output an image from the ACF options field with Timber/Twig?我如何 output 使用 Timber/Twig 从 ACF 选项字段中获取图像?

Below is what I have now, but unfortunately it isn't working.以下是我现在拥有的,但不幸的是它不起作用。 I just can't get it done.我就是无法完成它。 What am I doing wrong?我究竟做错了什么?

Timber controller木材 controller

$context['theme_options'] = get_fields('options');

Twig file Twig 文件

<img src="{{ Image(options.footer_logo).src }}" />

As @DarkBee mentioned in a comment to your question , you're using options instead of theme_options in your Twig file.正如@DarkBee对您的问题的评论中提到的那样,您在 Twig 文件中使用options而不是theme_options Try using this:尝试使用这个:

Twig file Twig文件

<img src="{{ Image(theme_options.footer_logo).src }}" />

The rest seems to be looking good. rest 看起来不错。

In case you want to check what's inside theme_options in Twig, you can use the dump() function:如果您想检查theme_options中的 theme_options 中的内容,可以使用dump() function:

{{ dump(theme_options) }}

Twig File: Twig 档案:

<img src="{{ Image(options.footer_logo).src }}"  alt="{{ Image(options.footer_logo).alt }}"/>

This code is accessible without adding any code to the timber controller.无需向木材 controller 添加任何代码即可访问此代码。

If you want to add specifically inside the timer controller for options page acf then use context variable in the twig file likes so:如果你想在计时器 controller 中专门为选项页面 acf 添加,然后在 twig 文件中使用上下文变量,如下所示:

Timber Controller:木材Controller:

$context['theme_options'] = get_fields('options');

Twig File: Twig 档案:

<img src="{{ Image(theme_options.footer_logo).src }}" alt="{{ Image(theme_options.footer_logo).alt }}"/>

For more information use this link below:Timber Documentation for Options Page with Advance Custom Field有关更多信息,请使用以下链接:带有高级自定义字段的选项页面的木材文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM