是否可以链接到Timber模板中的其他静态页面?

目前, 要链接到”常见问题”页面, 我需要以下内容:

Check out our <a href="{{ site.link }}/faq">FAQ</a> page.

但是, 我希望能够链接到WordPress主题中的其他内部页面, 而无需在其后手动编写URL参数。就像是:

Check out our <a href="{{ site.link('faq') }}">FAQ</a> page.

这在Timber中不可能吗?我检查了所有文档, 但没有看到任何引用, 但我觉得我一定缺少一些东西。


#1


你可以使用过滤器timber_context将页面添加到上下文中

add_filter('timber_context', 'add_to_context');

function add_to_context($context){
    /* this is where you can add your own data to Timber's context object */
    $extraLinks = [];
    $extraLinks['faq'] = get_permalink($faq_ID);
    $context['site']['extraLinks'] = $extraLinks;
    return $context;
}

这样你就可以调用你的树枝文件

Check out our <a href="{{ site.extraLinks.faq }}">FAQ</a> page.

资源

来源:

https://www.srcmini02.com/63607.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?