我一直在尝试加载fivestar模块,并在外部php文件中显示所选节点的评级小部件。我已经在页面上显示了评级小部件,但它只显示小部件的降级版本(非javascript,下拉小部件和"Rate“按钮)我查看了页面的源代码,但fivestar模块的javascript没有加载。我尝试使用以下函数加载javascript,但没有成功:
fivestar_add_js();$path = drupal_get_path('module','fivestar');drupal_add_js($path.'/js/fivestar.js','inline','footer');
以下是php文件中的代码:
//require the bootstrap include
require_once 'includes/bootstrap.inc';
//Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
fivestar_add_css();
// I have used one of the following two functions one at a time to test.
fivestar_add_js();
$path = drupal_get_path('module','fivestar');
drupal_add_js($path.'/js/fivestar.js', 'inline', 'footer');
$book = $_GET["book"];
$chap = $_GET["chap"];
$prob = $_GET["prob"];
$string = $book.'/'.$chap.'/'.$prob;
$query = "SELECT ctcr.nid FROM content_type_comments_ratings AS ctcr WHERE ctcr.field_problem_value = '".$string."'";
$result=db_query($query);
$row = db_fetch_array($result);
if(isset($row['nid']))
{
$nid = $row['nid'];
node_load(FALSE, NULL, TRUE);
$fivestar = node_load($nid, NULL, TRUE);
if (function_exists('fivestar_widget_form')) print fivestar_widget_form($fivestar);
}如果你能给我一个提示,或者指引我到网上阅读,我将不胜感激。非常提前感谢您。
发布于 2010-09-27 17:49:36
通过在“外部”页面/文件上执行所有这些操作,您可以绕过Drupal主题系统- drupal_add_js() (和fivestar_add_js(),因为它最终只是使用脚本标记)不会输出脚本标记本身,而只是确保它们将包含在page.tpl.php的$scripts变量中,然后page.tpl.php负责打印该变量的内容。由于您没有浏览页面模板,因此不会获得脚本标记。
您可以在外部文件中执行print drupal_get_js();,以输出通过drupal_add_js()添加的脚本作为快速修复,但请注意,这也将输出所有默认的drupal文件,这可能比您需要的文件多(但也可能包含fivestar所需的其他脚本,例如jquery)。或者,您必须自己创建所需的脚本标记。
至于阅读内容的提示,很难给你指出一些特别的东西,但你可能想要阅读the theming system的一般内容。
https://stackoverflow.com/questions/3796483
复制相似问题