【问题标题】:Put Html structure in drupal将Html结构放入drupal
【发布时间】:2014-01-06 12:04:58
【问题描述】:

您好,我创建了一个自定义的 drupal 模块,在我的模块中,我必须使用 while 循环从数据库中获取数据并在这个 ul,li 结构中打印数据。请让我知道我该怎么做

<ul class="catCol"><li><div class="itemLine"><div class="itemTitle"><a href="test_film.html"><font><font>test film</font></font></a></div><div class="itemCategory"><font><font>Pharmacy and Wholesale</font></font></div>
                                                                                                       <div class="itemDate"><span class="date"><font><font>11 Feb 2013</font></font></span></div>
                                                                                               </div>
                                                                                               <div style="clear:both;"></div>                        
                                                                                       </li>

我是 drupal 的新手,所以如果有人可以帮助我解决这个问题,那将是不胜感激的。

【问题讨论】:

  • 您可以像创建模板文件一样以更简洁的方式执行此操作。有关详细信息,请参阅 hook_theme。

标签: drupal drupal-7 drupal-modules drupal-views


【解决方案1】:
function your_callback(){
  return theme('custom_output', array('results' => $results)); // $results an array with results from database
}

function your_module_name_theme() {
 return array(
  'custom_output' => array(
   'file' => 'your_template.tpl.php', // place your file in 'templates' folder of your module folder
   'path' => drupal_get_path('module', 'your_module_name') .'/templates'
  )
 );
}

在您的“your_template.tpl.php”中,您也可以输入 php 和 html。从数据库中选择的结果可以从您的模板文件中的 $variables['results'] 变量中获得。

【讨论】:

  • 我希望我在几年前就看到了这个建议!这很容易成为最优雅和可维护的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多