我如何在 theme('node', $node) 和 drupal_render($node->content) 之间决定编程 $node 输出 [英] How do I decide between theme('node', $node) and drupal_render($node->content) for programmatic $node output

查看:18
本文介绍了我如何在 theme('node', $node) 和 drupal_render($node->content) 之间决定编程 $node 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个 $node,我试图在以下两种输出该 $node 的方式之间做出决定.

Given a $node, I'm trying to decide between the following two ways of outputting that $node.

要么

$output = theme('node', $node);

node_build_content($node);
$output = drupal_render($node->content);

它们似乎都给出了相似的结果,但是在我选择一种方式而不是另一种方式之前,有什么我应该考虑的吗?

They both seem to give similar results, but is there something I should consider before I choose one way over the other?

推荐答案

如果没有其他模块和主题通过主题层改变输出,则您的输出是相似的.

Your output is similar if there are no other modules and themes altering the output via the theme layer.

但是!如果您绕过主题层,当您安装模块或主题并更改使用主题层来更改节点输出的配置设置时,您可能会开始遇到意外行为.

But! If you bypass the theme layer, you'll probably start experiencing unexpected behaviour when you install modules or themes and change config settings that use the theme layer to alter the node's output.

简而言之,通过绕过主题层,您将错误构建到您的应用程序中.在您将应用程序交给开始更改 admin/

In short, by bypassing the theme layer, you're building error into your application. These error are likely to occur after you hand your application over to someone (a client perhaps) who starts changing settings in admin/

如果您有兴趣,请参阅装饰器模式.Drupal 广泛使用它.

See the decorator pattern if you're interested. Drupal uses this extensively.

http://en.wikipedia.org/wiki/Decorator_pattern

这篇关于我如何在 theme('node', $node) 和 drupal_render($node->content) 之间决定编程 $node 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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