如何为特定内容类型编辑或添加节点主题模板? [英] How can I theme the template for edit or add a node for a specific content type?

查看:25
本文介绍了如何为特定内容类型编辑或添加节点主题模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为模板设置主题以进行编辑或为特定内容类型添加节点.
例如,我使用文件 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.

这篇关于如何为特定内容类型编辑或添加节点主题模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆