TImber 2.0 错误

问题描述 投票:0回答:1

我正在尝试升级到 Timber 2.x,但不断遇到模板位置错误。

我从

Timber::$locations[] = 
切换到使用
timber/locations
过滤器;起初它不喜欢在 $paths 中添加
string
,所以它们是索引 0 数组,但现在我得到:

foreach() 参数必须是 array|object 类型,在 wood/timber/src/Loader.php 第 289 行给出 null。

这是我的

$paths
的转储(省略了完整的本地路径):

array (size=9)
  '__main__' => 
    array (size=7)
      0 => string 'theme-child/views' (length=87)
      1 => string 'theme/views' (length=76)
      2 => string 'theme-child/' (length=82)
      3 => string 'theme-child/views/' (length=88)
      4 => string 'theme/' (length=71)
      5 => string 'theme/views/' (length=77)
  0 => 
    array (size=1)
      0 => string 'mu-plugins/my-libutils/views' (length=84)
  1 => 
    array (size=1)
      0 => string 'plugins/my-content-block/views' (length=86)
  2 => 
    array (size=1)
      0 => string 'plugins/my-item-scheduling/views' (length=88)
  3 => 
    array (size=1)
      0 => string 'plugins/my-location/views' (length=81)
wordpress timber
1个回答
0
投票

要注册自定义位置,您需要将密钥传递给路径数组。

例如:

add_filter('timber/locations', function ( $paths ) {
   $paths['some_key'] = [
       $dirPath . '/views',
       //add more paths if needed
   ];

   return $paths;
});

有关更多详细信息,请参阅 Timber 2.0 文档

© www.soinside.com 2019 - 2024. All rights reserved.