gpt4 book ai didi

Drupal 表单模板建议

转载 作者:行者123 更新时间:2023-12-04 14:23:37 24 4
gpt4 key购买 nike

我正在尝试使用以下方法创建 drupal 表单建议:

function pfe_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__'. $variables['element']['#id'];
}
但在创建 之后表单--user-login-form.html.twig ,drupal 不考虑这个模板,但它总是使用 form.html.twig .
这是 html 评论:
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form' -->
<!-- FILE NAME SUGGESTIONS:
* form--user-login-form.html.twig
x form.html.twig
-->
<!-- BEGIN OUTPUT from 'core/themes/stable/templates/form/form.html.twig' -->
添加 HOOK_theme() 后:
function pfe_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__'.$variables['element']['#id']; //form--user-login-form.html.twig
}

function pfe_theme($existing, $type, $theme, $path) {

return [
'form__user-login-form' => [
'#theme' => 'form--user-login-form',
'render element' => 'form',
],
];

}
我收到此错误:

Twig_Error_Loader: Template "themes/pfe/templates/form--user-login-form.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "themes/pfe/templates/form--user-login-form.html.twig" in the Drupal theme registry.). in Twig_Loader_Chain->getCacheKey() (line 43 of /home/marwen/workspace/pfe/themes/pfe/templates/block/block--userlogin.html.twig).

最佳答案

使用“str_replace”将“-”替换为“_”,例如:

$suggestions[] = 'form__' . str_replace('-','_', $variables['element']['#id']);

关于Drupal 表单模板建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com