如何为特定内容类型编辑或添加节点主题模板?

2021-12-29 00:00:00 templates preprocessor php drupal drupal-6

我想为模板设置主题以进行编辑或为特定内容类型添加节点.
例如,我使用文件 page-node-{add|edit}.tpl.php(取决于我需要添加或编辑的内容)来对所有内容类型表单进行主题化.

I want to theme the template for edit or add a node for a specific content type.
For example, to theme all the content type forms I use the file page-node-{add|edit}.tpl.php (depending what I need to do add or edit).

但我没有找到自定义节点类型的模板名称,例如 Products.

But I didn't found the template name for a custom node type, for example Products.

我只需要为产品设置主题,而不需要为其他内容类型设置主题.

I need to theme only for Products, but not for the other content types.

我尝试过 page-node-edit-product.tpl.phppage-node-product-edit.tpl.php 但没有成功.

I've tried with page-node-edit-product.tpl.php and page-node-product-edit.tpl.php but no luck.

推荐答案

嗯.可能有更好的方法,但是预处理函数呢.

Hmm. There may be a better way but what about a preprocess function.

我对 Drupal 还是很陌生,所以我可能会尝试这样的事情[代码可能不起作用]:

I'm still really new to Drupal, so I would maybe try something like this [code may not work]:

<?php
function themeName_preprocess_page(&$vars, $hook) {
  if ((arg(0) == 'node') && (arg(1) == 'add' && arg(2) == 'product')) {
    $vars['template_files'][] =  'page-node-add-product';
  }
}
?>

创建新的预处理函数后,请务必清除缓存和主题注册表.

Be sure to clear cache and theme registry after making new preprocess functions.

相关文章