如何为模板进行主题编辑或添加特定内容类型的节点? [英] How can I theme the template for edit or add a node for a specific content type?
问题描述
我想主题模板进行编辑或添加特定内容类型的节点。
例如,要主题所有内容类型表单,我使用文件 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).
但是我没有找到一个自定义节点类型的模板名称,例如产品。
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.php
和 page-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屋!