Question

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.

Was it helpful?

Solution

Suppose 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 come 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

OTHER TIPS

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.com/en/latest/reference/assets.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top