问题描述
我有一个半复杂的灵活内容组件,该组件访问一个postpost对象,该对象包含一个带表情的ACF字段。
换句话说,弹性内容-> PostObject->未嵌入
但是我想提取原始的OEmbed链接以放入其自己的“ A标签”,该标签将把人们带到视频源。
我研究了以下问题:
https://github.com/timber/timber/issues/1211
https://github.com/timber/timber/issues/1423
相似,但在我看来似乎不起作用。
有没有办法
A)拔出Twig模板中的链接或
B)扩展Timber以仅返回PostObject中某处的链接吗?
解决方法
我建议在您的 php 中提取链接,然后将其添加到上下文中:
// Load value.
$iframe = get_field('oembed');
// Use preg_match to find iframe src.
preg_match('/src="(.+?)"/',$iframe,$matches);
$src = $matches[1];
// Add to timber/twig context
$context['iframe_src'] = $src