【发布时间】:2017-11-16 13:06:29
【问题描述】:
在我的自定义模块中,我有以下代码:
public function url() {
$current_path = \Drupal::service('path.current')->getPath();
return $current_path;
}
如何在我的树枝模板中使用此功能?
注意:我知道我可以更轻松地获得当前路径。我只指定了这个函数,所以我可以了解在 twig 中使用自定义 php 函数的想法。
【问题讨论】:
-
Drupal 有一个很好的文档! :-) drupal.org/docs/8/theming/twig/functions-in-twig-templates