JMSTwigJsBundle
JMSTwigJsBundle copied to clipboard
"goog is not defined" in production
Howdy,
I've been using this package to develop a couple templates that are only loaded via javascript. Everything works great in development. Templates are loaded as follows:
In my base.twig.html....
{% javascripts
"@MyAppBundle/Resources/views/Profile/modal.profile.html.twig"
"@MyAppBundle/Resources/views/Signup/modal.signup.html.twig"
filter="twig_js,yui_js" %}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
However, when I go to production I dump out the assets and and attempt to load the page, I get:
Uncaught ReferenceError: goog is not defined
It seems like the templates aren't getting compiled correctly for production. My understanding is that Google's closure library should be compiled (with only the required features) into the template itself. This seems work during development, but is not happening when I dump the assets to the filesystem for production usage.
Any thoughts on what I could be doing wrong here?
Did you include twig.js's runtime code (twig.js
or twig.dev.js
)?
Hmm. I think this may somehow be related to the fact that I symlinked twig.js into my AppBundle's Resources\public\js directory. I was pulling in twig.js like this:
{% javascripts
'@MyAppBundle/Resources/public/js/*'
filter='?yui_js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
However, for some reason it doesn't compile in twig.js if I am using a symlink and I use a wildcard (*) to pull in JS files. I fixed this by explicitly listing each javascript file to load instead of using the wildcard. This seems to be an issue with assetic (maybe... this seems like reasonable behavior anyways) and not JMSTwigJsBundle.
Thanks for pointing me in the right direction.
On a side note, is this the "appropriate" way to include Twig.js? I couldn't figure out how to load in the resource from the source bundle so I just symlinked it.
@ajbdev See the closed How should twig.js be included? issue.
{% javascripts
'%kernel.root_dir%/../vendor/jms/twig-js/twig.js'
...
Just had the same problem: "goog is not defined" .
Fixed by using the good twig.js file. (i was using the src-js/twig.js file)
Just had the same problem too: In my composer.json file I had only: "jms/twig-js-bundle" : "dev-master" And I had the twig.js file using bower
To fix, I just added in composer.json: "jms/twig-js" : "dev-master" , removed the twig.js line in bower.json and change to '%kernel.root_dir%/../vendor/jms/twig-js/twig.js' in my layout as specified above
works perfect, thanks (ps: and thanks for the bundle)
Same problem : "goog is not defined"
-
composer.json : "jms/twig-js-bundle": "dev-master"
-
layout.html.twig : {% javascripts '%kernel.root_dir%/../vendor/jms/twig-js/twig.js' '@AppBundle/Resources/views/Model/_item.twig' output='js/templates.js' filter="twig_js" %}
{% endjavascripts %}
and i can see in my templates.js : ... goog.require('twig'); goog.require('twig.filter'); ...