tsdtsdtsd Posted November 2, 2016 Share Posted November 2, 2016 Hi there, I recently updated to PW 3 and I'm using the AUTO-mode for the compiler. Everything worked like a charm, but now I'm getting a strange behavior which I would classify as a bug. I have the following in a template (which I'm including in the sites real template): <script> require(['hljs'], function(hljs) { hljs.initHighlighting(); }); </script> Plain old HTML+JS. Now, when I open up the site, the compiler made this: <script> require(\ProcessWire\wire('files')->compile(['hljs'],array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)), function(hljs) { hljs.initHighlighting(); </script> Seems to me that the compiler touches something that it should not. I couldn't find anything related here... bare with me if this is something well known. Cheers Link to comment Share on other sites More sharing options...
BitPoet Posted November 2, 2016 Share Posted November 2, 2016 The compiler, unfortunately, isn't really picky about things. It touches keywords like "require" and "include" inside and outside of the "real" PHP code, including comments. So, the quick solution would be to load hljs the classic way (<script src=...>). 2 Link to comment Share on other sites More sharing options...
tsdtsdtsd Posted November 2, 2016 Author Share Posted November 2, 2016 Hi BitPoet, thanks for your answer. Sadly your solution is not an option for this site. Guess I will have to set proper namespaces by myself or find another workaround. Link to comment Share on other sites More sharing options...
Robin S Posted November 2, 2016 Share Posted November 2, 2016 4 hours ago, tsdtsdtsd said: I have the following in a template (which I'm including in the sites real template): <script> require(['hljs'], function(hljs) { hljs.initHighlighting(); }); </script> Could this go in a linked JS file rather than directly in the template? Link to comment Share on other sites More sharing options...
Zeka Posted November 2, 2016 Share Posted November 2, 2016 You can try to use the third option in file compiler options of template. https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/#new-compiler-option-for-templates or // FileCompiler=0 https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/#how-to-bypass-the-file-compiler 3 Link to comment Share on other sites More sharing options...
horst Posted November 3, 2016 Share Posted November 3, 2016 You may also add a "namespace ProcessWire" into the first line of that template file and set the filecompiler to 0 / none for only that template. But, if you started to work with PW3 now, and will do so in the future, I suggest to always use the namespace ProcessWire in your template files (and sub files) and skip the file compiler completly for all template related stuff! Here, in template section, you have full control, other then in modules section, if you want to use third party modules that are not written as native PW 3 versions. 2 Link to comment Share on other sites More sharing options...
ottogal Posted November 3, 2016 Share Posted November 3, 2016 1 hour ago, horst said: always use the namespace ProcessWire in your template files (and sub files) and skip the file compiler completly for all template related stuff! "subfiles" here means partials to be included? And even more? Hanna code? Link to comment Share on other sites More sharing options...
horst Posted November 3, 2016 Share Posted November 3, 2016 1 hour ago, ottogal said: "subfiles" here means partials to be included? And even more? Hanna code? Yes, everything that you may somehow "include" into template files. Maybe, physically every php file under /site/templates/. Link to comment Share on other sites More sharing options...
tsdtsdtsd Posted November 3, 2016 Author Share Posted November 3, 2016 Thanks for all the answers guys. I changed the JS structure a bit to solve my problem. There are enough ways around this problem, but I still want to point out that I think that any kind of automation should be fail-safe as possible. A totally generic regex is not slightly fail-safe. It's not even code related, I could have "require(..." as a static text on a page. Don't get me wrong, I don't want to bash PW. As I said, I think there are enough ways to work around this problem. But an automation should be sane or at least point out it's obvious traps and disadvantages in the first place. Anyway, cheers for your help! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now