简体   繁体   中英

Exclude external javascript file from loading

I have a problem. In layout.phtml I load javascript file which I need in all pages except few:

$this->headScript()->prependFile($this->basePath('js.js'), 'text/javascript');

echo $this->headScript()

How can I exclude this javascript in index.phtml file which uses layout.phtml ?

You can do it like this:

if (__FILE__ != $YOUR_PATH_NAME) {
  $this->headScript()->prependFile($this->basePath('js.js'), 'text/javascript');
  echo $this->headScript()
}

Replace $YOUR_PATH_NAME with the actual path. This script should execute snippet inside if block only if it's not on the index page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM