[英]Zend Framework 2:: why inlineScript()->captureStart() is not working in layout.phtml
I include JS
file of my theme using $this->inlineScript()->appendFile()
in layout.phtml
. 我在
layout.phtml
使用$this->inlineScript()->appendFile()
包含主题的JS
文件。
After that I try to add some inline jquery
code using $this->inlineScript()->captureStart()
method. 之后,我尝试使用
$this->inlineScript()->captureStart()
方法添加一些内联jquery
代码。
The jquery
code is not showing but if I include that in action view page then jquery
code is showing fine. jquery
代码未显示,但是如果我在操作视图页面中包含该代码,则jquery
代码将显示正常。
Can anybody guess what I am missing. 有人能猜出我在想什么。
Here is my code snippets. 这是我的代码段。
echo $this->inlineScript()->appendFile($this->basePath() . '/assets/plugins/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 7',))
->appendFile($this->basePath() . '/assets/plugins/excanvas.min.js', 'text/javascript', array('conditional' => 'lt IE 7',))
->appendFile($this->basePath('/assets/plugins/jquery-1.10.2.min.js'));
$this->inlineScript()->captureStart();
echo <<<JS
jQuery(document).ready(function() {
App.init(); // initlayout and core plugins
Index.init();
Index.initJQVMAP(); // init index page's custom scripts
Index.initCalendar(); // init index page's custom scripts
Index.initCharts(); // init index page's custom scripts
Index.initChat();
Index.initMiniCharts();
Index.initDashboardDaterange();
Index.initIntro();
Tasks.initDashboardWidget();
});
JS;
$this->inlineScript()->captureEnd();
If you capture additional scripts after you have echo'd the inlineScript helper output, how would you expect your additional code to be output? 如果您在回显了inlineScript帮助程序输出后捕获了其他脚本,您将如何期望输出其他代码? You either need to move your inline script above the echo in your layout, or move the echo to the end:
您需要将内联脚本移动到布局中的回显上方,或者将回显移至末尾:
$this->inlineScript()->appendFile($this->basePath() . '/assets/plugins/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 7',))
->appendFile($this->basePath() . '/assets/plugins/excanvas.min.js', 'text/javascript', array('conditional' => 'lt IE 7',))
->appendFile($this->basePath('/assets/plugins/jquery-1.10.2.min.js'));
$this->inlineScript()->captureStart();
echo <<<JS
jQuery(document).ready(function() {
App.init(); // initlayout and core plugins
Index.init();
Index.initJQVMAP(); // init index page's custom scripts
Index.initCalendar(); // init index page's custom scripts
Index.initCharts(); // init index page's custom scripts
Index.initChat();
Index.initMiniCharts();
Index.initDashboardDaterange();
Index.initIntro();
Tasks.initDashboardWidget();
});
JS;
$this->inlineScript()->captureEnd();
echo $this->inlineScript();
It works when you do it in the action because the action is rendered before the layout. 当您在操作中执行此操作时,它会起作用,因为操作在布局之前呈现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.