javascript - headScript()->appendFile has the same behaviour as headScript()->prependFile from view -
i ran problem. appendfile not seem work view. has same behaviour if change prependfile.
layout.phtml
<!doctype html> <html lang="en" dir="ltr"> <head> <?php $this->headscript()->appendfile('http://code.jquery.com/ui/1.10.3/jquery-ui.js'); $this->headscript()->appendfile('/theme/javascripts/application.js'); $this->headscript()->appendfile('/js/own.js'); ?> </head> <body> <?php echo $this->layout()->content; ?> <?php echo $this->headscript() ?> </body> </html>
index.phtml
<?php $this->headscript()->appendfile('/js/another.js') ?>
output
<!doctype html> <html lang="en" dir="ltr"> <head> </head> <body> <script type="text/javascript" src="/js/another.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script type="text/javascript" src="/theme/javascripts/application.js"></script> <script type="text/javascript" src="/js/own.js"></script> </body> </html>
as can see /js/another.js first js. that's not want, want put last. knows what's wrong ?
/js/another.js
@ beginning because layout.phtml
called first , when call <?php echo $this->layout()->content; ?>
calls index.phtml
file.
now in code you've:
<?php echo $this->layout()->content; ?>
<?php echo $this->headscript() ?>
so it's calling layout()
, hence index.phtml
, calling headscript()
has rest of them. appending js
mentioned in index.phtml
, appends rest headscript()
. try other way around...
you should try:
<!doctype html> <html lang="en" dir="ltr"> <head> <?php $this->headscript()->appendfile('http://code.jquery.com/ui/1.10.3/jquery-ui.js'); $this->headscript()->appendfile('/theme/javascripts/application.js'); $this->headscript()->appendfile('/js/own.js'); ?> </head> <body> <?php echo $this->headscript() ?> <?php echo $this->layout()->content; ?> </body> </html>
ideally should output scripts in <head>
section.
Comments
Post a Comment