Reputation: 75
I don't know how to import one file javascript in my new module Zend Framework 2.
The code is located in: vendor\name-module\js\test.js
Can anyone help?
Upvotes: 0
Views: 634
Reputation: 27058
what about:
$this->headScript()->prependFile('../../vendor/name-module/js/test.js');
../
goes back to public ../../
goes to the main application
make sure to echo $this->headScript();
in a layout or view
If you want to use use a javaScript file per controller use it like this:
use Zend\View\Renderer\PhpRenderer;
...
public function indexAction()
{
$headScript = new PhpRenderer();
$headScript->headScript()->appendFile('../../vendor/name-module/js/test.js');
}
edit:
u can use the public
folder. make a folder called js
and put the JavaScript files there, then use:
$headScript->headScript()->appendFile('/js/test.js');
Upvotes: 1