admin管理员组文章数量:1401208
Consider following two files:
// view/index.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/jquery.js");
// view/about/about.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/x.js");
About will generated like:
<script src="javascript/x.js">
<script src="javascript/jquery.js">
But x.js
file is depended on jquery.js
so it should placed before it.
Consider following two files:
// view/index.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/jquery.js");
// view/about/about.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/x.js");
About will generated like:
<script src="javascript/x.js">
<script src="javascript/jquery.js">
But x.js
file is depended on jquery.js
so it should placed before it.
2 Answers
Reset to default 4Suppose you have the following structure:
app/views/index.phtml
app/views/about/index.phtml
You can define the following in the app/views/index.phtml
at the top
<?php echo \Phalcon\Tag::javascriptInclude("javascript/jQuery.js"); ?>
<?php echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); ?>
and then in the app/views/about/index.phtml
<?php echo \Phalcon\Tag::javascriptInclude("javascript/x.js"); ?>
That would get the jQuery.js
and myother.js
scripts to load before the x.js
does, since the x.js
will e in the master view with the
<?php echo $this->getContent() ?>
Alternatively, you could set this in your master view:
<?php echo \Phalcon\Tag::javascriptInclude("javascript/jQuery.js"); ?>
<?php echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); ?>
<?php if ($is_about) { echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); } ?>
and in your About controller
$this->view->setVar('is_about', TRUE);
HTH
Not sure if it fits the OP's use case, but for others searching, this pattern is pretty useful:
class MyController extends Phalcon\Mvc\Controller
{
public function initialize()
{
$this->assets->addJs("/path/to/myjs.js");
[...etc]
docs: http://docs.phalconphp./en/latest/reference/assets.html
本文标签: phpIncluding JavaScript in Phalcon viewsStack Overflow
版权声明:本文标题:php - Including JavaScript in Phalcon views - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744301018a2599583.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论