You are here

16 常见问题

admin 的头像
Submitted by admin on 星期五, 2015-09-18 06:43

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

很多人经常会问这样的问题,Drupal是怎么把这些模板文件转为HTML内容返回的呢?我们前面已经讲过了,预处理函书里面,可以为模板文件设置变量。现在的问题是怎么最终使用模板文件生成HTM?这个工作,是在下面的函数中实现的:

 

function theme_render_template($template_file, $variables) {

  extract($variables, EXTR_SKIP);               // Extract the variables to a local namespace

  ob_start();                                   // Start output buffering

  include DRUPAL_ROOT . '/' . $template_file;   // Include the template file

  return ob_get_clean();                        // End buffering and return its contents

}

    把模板文件和变量传递了过来,然后返回生成的HTML片段。



Drupal版本: