防止木材在与ACF_Blocks一起使用时逃逸"&&"



这是我的木块渲染函数

function render_swiper_block($block, $content = '', $is_preview = false)
{
$context = Timber::context();
// Store block values.
$context['block'] = $block;
// post id
$context['id'] = get_the_id();
// Store field values.
$context['fields'] = get_fields();
// Store $is_preview value.
$context['is_preview'] = $is_preview;
// Render the block.
Timber::render('admin/swiper.twig', $context);
}

当我从swiper.twig内的脚本标签中启动滑动器滑块时,问题就出现了,如下所示:

<script type='text/javascript'>
let interval = setInterval(function() {
if (window.hasOwnProperty('Swiper')) {
let swiper = {
el: '.{{ block.id }}',
instance: '',
breakpoint: 1023,
active: false,
config: {
loop: true,
centeredSlides: true,
slidesPerView: 'auto',
spaceBetween: 1,
// Navigation arrows
navigation: {
nextEl: '.arrow-next',
prevEl: '.arrow-prev',
},
},
}
swiper.instance = new Swiper(swiper.el, swiper.config)
if (window.innerWidth > swiper.breakpoint) {
swiper.active = true
}
addEventListener('resize', debounce(() => {
if (window.innerWidth > swiper.breakpoint && swiper.active === false) {
swiper.instance = new Swiper(swiper.el, swiper.config)
swiper.active = true
}
if (window.innerWidth <= swiper.breakpoint && swiper.active === true) {
swiper.instance.destroy(true, true)
swiper.active = false
}
}, 300))
clearInterval(interval);
}
}, 100);
</script>

post.content转义&&,而打印&#038;&#038;,我知道它的WordPress过滤器apply_filters('te_content',$content(可以做到这一点。但是,对于我的用例,有办法绕过它吗?

使用过{{ var|raw }}吗?

原始过滤器将值标记为"安全",这意味着在启用了自动转义的环境将不会如果raw是应用于它的最后一个筛选器,则转义。

参考:https://twig.symfony.com/doc/2.x/filters/raw.html

最新更新