我想为模板设置主题以进行编辑或为特定内容类型添加节点。
例如,为我使用文件的所有内容类型表单设置主题page-node-{add|edit}.tpl.php
(取决于我需要添加或编辑的内容)。
但是我没有找到自定义节点类型的模板名称,例如 Products。
我只需要为产品设置主题,而不需要为其他内容类型设置主题。
我试过了page-node-edit-product.tpl.php
,page-node-product-edit.tpl.php
但没有运气。
我想为模板设置主题以进行编辑或为特定内容类型添加节点。
例如,为我使用文件的所有内容类型表单设置主题page-node-{add|edit}.tpl.php
(取决于我需要添加或编辑的内容)。
但是我没有找到自定义节点类型的模板名称,例如 Products。
我只需要为产品设置主题,而不需要为其他内容类型设置主题。
我试过了page-node-edit-product.tpl.php
,page-node-product-edit.tpl.php
但没有运气。
唔。可能有更好的方法,但是预处理函数呢?
我对 Drupal 还是很陌生,所以我可能会尝试这样的事情[代码可能不起作用]:
<?php
function themeName_preprocess_page(&$vars, $hook) {
if ((arg(0) == 'node') && (arg(1) == 'add' && arg(2) == 'product')) {
$vars['template_files'][] = 'page-node-add-product';
}
}
?>
制作新的预处理功能后,请务必清除缓存和主题注册表。
这就是我认为的“正确”方法。
从节点模块:
$form['#theme'] = array($node->type .'_node_form', 'node_form');
所以 Drupal 会尝试主题化 'product_node_form'
所以你可以创建一个实现这个的模块。
您将需要实现 [hook_theme][1],并提供一个函数或模板。
你可能会发现使用 [hook_form_alter][2] 添加一些类和普通的 CSS 来改变外观更容易。
function themename_preprocess_page(&$vars) {
// Add per content type pages
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use hyphens.
// If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
}
}
在template.php中加入以上代码
然后创建几个 tpl 文件
1) 页面内容类型.tpl.php
在显示和编辑内容时使用
2) page-node-add-contenttype.tpl.php
添加该内容类型时使用。
与drupal 6一起使用。
我自己是一个drupal菜鸟,但是像这样的东西(可能需要更多)会起作用吗?
function phptemplate_node_form($form)
{
switch ($form['#node']->type) {
case 'product':
return theme_render_template(path_to_theme().'/node-edit-product.tpl.php', array('form' => $form));
default:
return theme_node_form($form);
}
}
对我来说同样的问题。提示在哪里插入代码:
<?php
function themeName_preprocess_page(&$vars, $hook) {
if ((arg(0) == 'node') && (arg(1) == 'add' || arg(2) == 'product')) {
$vars['template_files'][] = 'page-node-add-product';
}
}
?>
它在 template.php 或 page-node - {add|edit}-example.tpl.php 中输入?
我把它放在我的主题目录中的 template.php 文件中:
function MYTHEMENAME_theme($existing, $type, $theme, $path) {
return array(
// tell Drupal what template to use for the edit form
family_individual_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'node-family_individual-edit'
)
);