在为节点表单设置主题时建议不同的模板
function posts_theme($existing, $type, $theme, $path) {
return array(
'post_node_form' => array(
'arguments' => array('form' => NULL),
'template' => VARIABLE,
)
);
}
这是建议模板在 Drupal 6 中渲染“post_node_form”的方法。但是我想从 2 个不同的路径获取节点编辑表单:
- 通过 AJAX 通过 drupal_get_form('post_node_form')
- 通过默认节点/添加/发布
如果我根据路径(或任何其他条件)替换“VARIABLE”,它不会工作,因为它看起来?模板的名称已缓存,您需要刷新缓存才能刷新它。
建议不同的表单模板有什么解决方案吗?
笔记。这不是节点模板的情况,(然后您可以将模板建议放在预处理挂钩中)。这是关于节点 FORM 的。
function posts_theme($existing, $type, $theme, $path) {
return array(
'post_node_form' => array(
'arguments' => array('form' => NULL),
'template' => VARIABLE,
)
);
}
This is the way of suggesting a template to render the 'post_node_form' in Drupal 6. BUT I want to get the node editing form from 2 different paths:
- via AJAX through drupal_get_form('post_node_form')
- via default node/add/post
If I replace "VARIABLE" depending on the path (or whatever other condition), it will not work because it seems? the name of the template is cached and you need to flush caches to refresh it.
Any solution of suggesting different form templates?
NOTE. This is not the case of node template, (then you can put the template suggestions in the preprocess hooks). It's about node FORM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加此函数/或修改主题的 template.php 中是否存在:
Add this function/or modify if exists into template.php of your theme:
好吧,我回答我自己的问题:
解决方案的关键是钩子
preprocess_NAME_OF_MY_FORM
,它在每次页面加载时执行,可以在您的模块或主题中。因此,就我而言,我在“posts”模块中写道:
我的模块文件夹中有文件
post-form-custom.tpl.php
和post-form-default.tpl。 php
Ok, I answer my own question:
The key of the solution is the hook
preprocess_NAME_OF_MY_FORM
, that is executed every page load and can be in your module or your theme.So in my case, I wrote in my "posts" module:
I had in my module folder the files
post-form-custom.tpl.php
andpost-form-default.tpl.php