如何获取当前drupal主题的路径?
The Drupal API has drupal_get_path($type, $name)
which will give the path of any particular theme or module. What if I want the path of the current theme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
使用
path_to_theme
函数。Use the
path_to_theme
function.这应该有效(doc):
this should work (doc):
在 D6 中,path_to_theme() 可能不会按照您期望的方式运行,具体取决于您使用它的方式。 如果您在任何主题预处理函数之外使用它,那么它可能会给您想要的东西,但是如果在模块的主题/预处理挂钩函数的上下文中调用它......它将指向该模块路径宣告了主题。
前任。 如果我有一个主题“my_theme”和我的模块“my_module”,它使用预处理挂钩覆盖论坛主题,则在我的模块中调用path_to_theme():例如my_module_preprocess_forums()...将返回“forums”,而不是“my_theme”正如人们所预料的那样。
如果你问我的话,非常果味。
In D6 path_to_theme() may not behave in a way you expect depending on how you are using it. If you are using it outside any theme preprocess functions, then it will probably give you what you want, but if it is being called within the context of a module's theming/preprocess hook function... it will be pointing to the module path that declared the theme.
Ex. If i have a theme "my_theme" and my module "my_module" which is overriding the forum themes using the preprocess hooks, calling path_to_theme() within my module: e.g. my_module_preprocess_forums()... will return "forums", and not "my_theme" as one might expect.
Very fruity if you ask me.
在 Drupal 8 中,如果您需要在管理主题处于活动状态时获取活动主题路径,您可以获取默认主题路径:
In Drupal 8, if you need to get the active theme path when you have the admin theme active you can fetch the default theme path:
在 Drupal 7 中,为了获取当前主题的路径,我们可以使用:
path_to_theme() 函数。
In Drupal 7, for getting current theme's path, we can use:
path_to_theme() function.
在 Drupal 8 中
In Drupal 8
在 Drupal 5 中,您可以简单地使用: path_to_theme()
这将为您提供从 Drupal 根目录到特定主题目录的完整路径。 请注意,它不包含尾部斜杠。
在 Drupal 6 中,其行为略有不同。 如果您从页面内调用它,它将调用当前正在执行主题的任何内容...无论是您的主题、模块等。以下是 API 文档中的关键引用:
来源:http://api.drupal.org/api/function/path_to_theme
In Drupal 5, you can simply use: path_to_theme()
This will give you a complete path from the root of Drupal to the specific theme directory. Be aware, it does not include a trailing slash.
In Drupal 6, this behaves just a bit differently. If you call it from within your pages, it will call whatever is currently doing the theming... whether that is your theme, a module, etc. Here's the key quote from the API docs:
Source: http://api.drupal.org/api/function/path_to_theme
如果您已经知道主题名称
或
If you already know the theme name
or
对于 D8,主题文件夹可在预处理函数中使用:
page.html.twig:
For D8, the theme folder is available in preprocess functions:
page.html.twig: