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).
但我没有找到自定义节点类型的模板名称,例如 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.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.
这篇关于如何为特定内容类型编辑或添加节点主题模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为特定内容类型编辑或添加节点主题模板?


- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01