2016-07-14 26 views

回答

1

我会用timber_context过滤器进行手动添加(或timber\context )在使用get_context时添加您自己的数据。

下面是如何增加一个菜单/导航(从Wiki page on TimberMenu)的例子:

add_filter('timber_context', function($context) { 
    /* So here you are adding data to Timber's context object, i.e... */ 
    $context['foo'] = 'I am some other typical value set in your functions.php file, unrelated to the menu'; 

    /* Now, in similar fashion, you add a Timber menu and send it along to the context. */ 
    $context['menu'] = new Timber\Menu(); // This is where you can also send a WordPress menu slug or ID 

    return $context; 
}); 

你必须做的就是最低数据到您的模板将为:

$context = Timber::get_context(); 

Timber::render('template.twig', $context);