如何在drupal hook_block中打印输出

发布于 2024-10-01 05:48:56 字数 805 浏览 1 评论 0原文

如何打印输出,如果我在函数中用 WHILE SNIPPET 编写,

下面是我的代码片段,我想打印检索到的结果,

我尝试了 echo ,

但我们不应该在 drupal 中使用 echo ,并且 drupal 设置消息函数用于调试目的,

所以如何打印本例中的输出,

function node_example_block($op='list',$delta=0){

    switch($op){
        case "list":
            $block[0]['info'] = t('THIS IS EXAMPLE NODE EXAMPLE ');
            return $block;
        case "view":    
            $block['subject'] = "THIS MY FIRST SAMPLE BLOCK";
            $block['content'] = drupal_get_form('display_node_title');

            return $block;
    }

}

function display_node_title(){

    $result = db_query("SELECT * FROM node");
    $output = '';
    while ($obj = db_fetch_object ($result)){
        $output .= $obj->title;
     }
    //drupal_set_message($output);
}

How to Print the output, if i written in WHILE SNIPPET in the function ,

Below is my snippet, i want print retrieved result ,

i tried echo ,

but we should not use echo in drupal, and drupal set message function for debug purpose ,

So how to print my output in this example ,

function node_example_block($op='list',$delta=0){

    switch($op){
        case "list":
            $block[0]['info'] = t('THIS IS EXAMPLE NODE EXAMPLE ');
            return $block;
        case "view":    
            $block['subject'] = "THIS MY FIRST SAMPLE BLOCK";
            $block['content'] = drupal_get_form('display_node_title');

            return $block;
    }

}

function display_node_title(){

    $result = db_query("SELECT * FROM node");
    $output = '';
    while ($obj = db_fetch_object ($result)){
        $output .= $obj->title;
     }
    //drupal_set_message($output);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛刀软妹 2024-10-08 05:48:56

您已通过 drupal_get_form 传递 display_node_title,但 display_node_title 不是表单函数。如果是的话,它将通过 Form API 构造一个 $form 数组,并在最后 return $form;

将: 更改

$block['content'] = drupal_get_form('display_node_title');

为:

$block['content'] = display_node_title();

并将: 添加

return $output;

display_node_title() 函数的末尾。

You're having display_node_title get passed through drupal_get_form, but display_node_title isn't a form function. If it were, it'd be constructing a $form array via the Form API and return $form; at the end.

Change:

$block['content'] = drupal_get_form('display_node_title');

to:

$block['content'] = display_node_title();

and add:

return $output;

to the end of your display_node_title() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文