Drupal文档教程翻译 - 自定义扩展的输出 - CCK(3)
本站原创编译,转载请给面子,尊重劳动果实,欢迎交流指正。
各位早,章鱼早,芭蕉早,闹不住菇早,新的一周开始了,清晨被大雨吵醒,隐约记得整整一周前也是同样的状况,老湿太给力了。Drupal文档中文翻译时间,继续上周的CCK输出自定义的话题,今天来看怎样自定义后台中原生的CCK输入表单(input form)。
要打造CCK原生的输出表单,我们需要做以下几件事情:
- 编辑template.php文件
- 创建node-content_type-edit.tpl.php模板文件
- 清空缓存
下面来看一个范例:
假设我们当前的内容类型叫做“account_registration”,当前的主题为“bluemarine”。
第一步,将下面的代码添加到template.php文件中:
接下来创建node-account_registration-edit.tpl.php模板文件:
//To REMOVE Title field
<?php unset($form['title']); ?>
<fieldset class=" collapsible">
<legend>Company Data</legend>
<?php
//NOTE: if you don't have Field Group then simply type:
// print drupal_render($form['field_accreg_company_name']['0']['value']);
print drupal_render($form['group_company']['field_company']['0']['value']);
print drupal_render($form['group_company']['field_street']['0']['value']);
?>
</fieldset>
<?php print drupal_render($form); ?>
<?php
// print_r($form); //Enable this to show all Array Variables of Form
?>
接下来针对一些具体需求看一下代码片段:
1.只渲染一个属性域的输入框:
<?php print drupal_render($form['group_company']['field_street']['0']['value']); ?>
2.渲染一个属性域组的输入:
<?php print drupal_render($form['group_company']); ?>
3.渲染一个下拉列表;和textfield类似,但是不需要最后的['0']['value']
<?php print drupal_render($form['group_company']['field_region']); ?>
4.去掉一个属性域的输入框:
<?php unset($form['title']); ?>
5.隐藏一个属性域的输入框:
<?php $form['title']['#access'] = FALSE; ?>
6.显示当前表单中所有的可用变量:
<?php print_r($form); ?>
7.根据权重为表单元素重新排序:
$form['buttons']['#weight'] = -50; // buttons at the top
8.输出按钮:
<?php print drupal_render($form['buttons']); ?>
9.为按钮重命名:
$form['buttons']['submit']['#value'] = 'Save to Database';
10.隐藏属性域组的输入:
$form['group_general']['#access'] = FALSE;
11.隐藏按钮:
$form['buttons']['submit']['#access']= FALSE;
译者:Viiiix7210
如需转载,请注明官方英文文档及本人译文的出处,谢谢。查看英文原文: Theme a CCK input form for CCK2
| < Prev | Next > |
|---|
