Jump to content

Recommended Posts

Posted

Getting closer to the ProcessWire 3.x stable release, version 3.0.14 focuses largely on updates and optimizations specific to recent GitHub issue reports. We also have optimizations and in-depth coverage of PW’s file compiler, some new options for required fields, along with a review of some best practices when working with fields. 

https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/

  • Like 13
Posted

Hello,

I am a little bit confused about the new file compiler template options.

I have a clean ProcessWire 3.0.15 dvns installation and the basic-page template. Now If I add the ProcessWire namespace to my template file

<?php namespace ProcessWire;

and set the file compiler for this template to "Auto" (default), it still compiles the template to site/assets/cache/FileCompiler/site/templates/basic-page.php.

Only if I set the file compiler to "No", of course, it doesn't compile. Shouldn't the "Auto" option detect if I had added the namespace manually and skip compiling the template? Also I noticed that, when I don't have the namespace added in my template file, the compiled files don't have the namespace added as well. Regardless of wich option (besides "No" of course).

Am I misunderstanding something and the namespace is added somewhere else or is this maybe a bug?

Posted

The file compiler does not add the namespace, but rather rewrites all instances, where class names where used without proper namespace.

new Page() => new \ProcessWire\Page()
new PageArray => new \ProcessWire\PageArray
if($page instanceof Page) => if($page instanceof \ProcessWire\Page)

Adding a namespace declaration to a file is not a good idea for the compiler, because it affects all used classnames, not only the processwire ones.

Posted

Adding a namespace declaration to a file is not a good idea, because it affects all used classnames, not only the processwire ones.

Honestly, I never worked with namespaces in PHP before. I just read in one of Ryan's blog posts, that you can add it to skip the file compiler.

So should I remove the namespace of my template files?

Posted

No, sorry. I meant it's not a good idea for the compiler to add a namespace declaration. You yourself can do what you want / need to do in your template files.

  • Like 1
Posted

Actually I don't need the ProcessWire namespace at all in my template files. I just thought it would be good to add it manually to avoid that my template files would get compiled unnecessary. But since that doesn't work, I think I will remove the namespace again and set the file compiler for my templates to "Auto", as recommended.  ;)

Posted
Now If I add the ProcessWire namespace to my template file
<?php namespace ProcessWire;

and set the file compiler for this template to "Auto" (default), it still compiles the template to site/assets/cache/FileCompiler/site/templates/basic-page.php.

Actually, this is the blog post in question: the one about ProcessWire 3.0.14

I have just tested and you are right, it does not seem to work (PW 3.0.15). I set all the "Use Compiled File?" settings to auto, cleared the template compile cache folder (/site/assets/cache/FileCompiler/site/templates) and the files keep coming back. And my template files start with namespace ProcessWire;

  • Like 1
Posted

The File Compiler may still compile the file, but that doesn't mean it'll use it. It can compile a file for no purpose other than to determine if there would be any differences provided by compilation. 

  • Like 2
Posted

The File Compiler may still compile the file, but that doesn't mean it'll use it. It can compile a file for no purpose other than to determine if there would be any differences provided by compilation. 

Thank you for clarifying this!

  • 4 weeks later...
Posted

Thank you for your great CMS!

I have a litte issue that is related to the FileCompiler (in version 3.0.17, actually):

One of my templates contains the line

<?php include('asides/_comments.php') ?>

This is compiled to

<?php  include(\ProcessWire\wire('files')->compile('asides/_comments.php') ,array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true))?>

which gives me a Parse Error: syntax error, unexpected ',' (line 71 of [...]/site/assets/cache/FileCompiler/site/templates/post.php)

Setting $config->templateCompile = false; helps - but I suppose this is not the way you meant it to be.

I have seen https://processwire.com/api/ref/wirefiletools/compile-include/

Are you trying to compile include() in my templates to $wireFileTools->compileInclude() or do you expect me to use compileInclude() myself?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...