drupal 6:如何从自定义模块获取数据到模板文件中 [英] drupal 6: how to get data from a custom module in to a template file

查看:17
本文介绍了drupal 6:如何从自定义模块获取数据到模板文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自定义模块在 example.com/frontpage 创建我的主页的内容.

im using a custom module to create the contents of my homepage at example.com/frontpage.

在模块中,我运行一个查询,以数组的形式获取我需要的数据.当我返回 theme('page', $my_array) 时,我得到了主页内的主页",即默认的 drupal 徽标和站点名称第二次显示在主要内容区域中.

in the module i run a query that gets the data i need, in an array. when i return theme('page', $my_array) i get the "homepage inside the homepage", ie the default drupal logo and sitename is displayed a second time in the main content area.

最好的方法是什么,创建一个特定的 tpl.php 文件,其内容应该是......?

what's the best way to go about this, create a specific tpl.php file, the contents of which should be ... ?

我意识到这是一个非常笼统的问题,但是在 2 个小时的尝试和阅读教程中,我并没有走得太远......

i realise its a very general question but in 2 hours of trying things out and reading tutorials ive gotten not very far at all ...

谢谢

推荐答案

如果我正确理解您的问题,您所要做的就是返回内容,而无需通过 theme_page 运行它.theme_page 获取您的内容并将其包装在站点模板中,因此在您的情况下手动调用它会复制模板.

If I'm understanding your question correctly, all you have to do is return the content without running it through theme_page. theme_page takes your content and wraps it in the site template, so calling it manually in your case is duplicating the template.

另一种解决方案是让页面的回调函数不返回任何内容,而是打印theme_page 的输出.如果回调函数未返回任何文本,则不会自动包含网站模板.

An alternate solution is to have your page's callback function not return anything, instead printing the output of theme_page. If a callback function returns no text, the site's template is not included automatically.

<?php

function mymodule_menu() {
  $items = array();

  $items['option1'] = array(
    'title' => 'Front page option #1',
    'access arguments' => array('access content'),
    'page callback' => 'mymodule_option1',
    'type' => MENU_CALLBACK,
  );

  $items['option2'] = array(
    'title' => 'Front page option #2',
    'access arguments' => array('access content'),
    'page callback' => 'mymodule_option2',
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function mymodule_option1() {
  // build HTML content here
  return $content;
}

function mymodule_option2() {
  // build HTML content here
  print theme('page', $content);
  return null;
}

这篇关于drupal 6:如何从自定义模块获取数据到模板文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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