如何在Drupal中使用主题Form API按钮?
-
06-07-2019 - |
题
Drupal的Form API的默认输出是:
<input id="edit-submit" class="form-submit" type="submit" value="Save" name="op"/>
我如何获得主题:
<button id="edit-submit" class="form-submit" type="submit">
<span>Save</span>
</button>
我需要内部span-tag,所以我可以使用滑门CSS技术。
我想我需要覆盖form.inc中的theme_button($ element),但到目前为止我的尝试都没有成功。
解决方案
如果使用普通的PHP主题(如Chameleon),主题化form_foo的基本思路是编写一个名为theme_form_foo()的函数。
你也可以通过为它声明一个主题函数来专门设置一个元素(比如这个按钮)。请参阅 https://api.drupal.org/api/drupal /developer%21topics%21forms_api_reference.html/7
请注意,对于D6,在这两种情况下,您都需要在主题注册表中声明该函数,否则Drupal将不会注意到此覆盖。这在D5中不是必需的。如果您正在使用phptemplate,那么您也需要它,尽管PHPtemplate会在表单案例之外处理注册表: http://drupal.org/node/132442#theme-registry
此文档可在a.d.o上找到。 : http://api.drupal.org/api/file/developer/topics/forms_api.html
其他提示
我现在有一个
的功能function mytheme_button($element) {
return "<button><span></span></button>"; # lots of code missing here for clarity
}
为了使其工作,我只是清除了缓存,Drupal注意到并自动使用它。
不隶属于 StackOverflow