2014-01-06 25 views
0

您好我已创建一个自定义的Drupal模块和我的模块中我有使用while循环来从数据库中的数据,这UL内打印数据,李structure.Please让我知道我怎么可以这样做将HTML结构在Drupal

<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,所以如果任何人都可以帮助我解决这个问题,这将是可观的。

+0

您可以为创建一个模板文件中的更清洁的方式做到这一点。有关更多信息,请参阅hook_theme。 – Zolyboy

回答

2
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']变量的模板文件中获得。

+0

我希望我看到了这条建议在几年前!这是最优雅和可维护的解决方案。 – Graham