[英]return acf image src in twig
i cant get the acf images to return.我无法让 acf 图像返回。
in my single-work.twig (view file) i have在我的单一作品中。我有
<img src="{{ Image(post.meta('laptop_image')).src }}" />
and in the single-work.php (controller file) template i have并在我有的单工作.php(控制器文件)模板中
$context['laptop_image'] = get_field('laptop_image');
i also tried我也试过
in single-work.php (controller file)在单一工作中。php(控制器文件)
$post->laptop_image = new Timber\Image($post->laptop_image);
in single-work.twig (view file)在单一作品中。twig(查看文件)
<img src="{{ post.laptop_image.src | resize(500, 300) }}" />
most of the time i get “unknown” as the result.. I used to get the image id returned but i cant remember how i got that… Any help would be great.大多数时候我得到“未知”的结果..我曾经得到返回的图像ID,但我不记得我是怎么得到的......任何帮助都会很棒。
full single-work.php全单工作。php
$context = Timber::context();
$timber_post = Timber::query_post();
$context['post'] = $timber_post;
$context['text_with_image_title'] = get_field('headline');
$context['text_with_image_text'] = get_field('description');
$post->laptop_image = new Timber\Image($post->laptop_image);
$context['ipad_image'] = get_field('ipad_image');
$context['iphone_image'] = get_field('iphone_image');
$context['text_with_image_btn_link'] = get_field('work_url');
$context['text_with_image_btn_label'] = 'Go to ' . $timber_post->post_title . ' Website';
$context['text_with_image_btn_target'] = '_blank';
if ( post_password_required( $timber_post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $timber_post->ID . '.twig', 'single-' . $timber_post->post_type . '.twig', 'single-' . $timber_post->slug . '.twig', '/pages/single-work.twig' ), $context );
}
var_dump($post->laptop_image); //returns image id
full code of work.twig完整的工作代码。twig
<div class="col-6 text-with-image__column text-with-image__column--image">
<div class="text-with-image__wrapper">
<img src="{{ post.laptop_image.src | resize(500, 300) }}" />
{{dump(post.laptop_image)}} //returns nothing
</div>
</div>
i realized i was using a macro and therefore我意识到我正在使用宏,因此
<img src="{{ Image(post.laptop_image).src }}" />
works fine, though it needs to be applied as the macro value of the new instance. <img src="{{ Image(post.laptop_image).src }}" />
工作正常,但它需要作为新实例的宏值应用。 Not just apart of the template.不仅仅是模板的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.