Jump to content

Recommended Posts

Posted

It took me a while to figure out what causes wireRenderFile() to fail processing its second (optional) parameter in ProcessWire 3.0.3, but finally I could pass those variables to the template file by using the "Yes (template file only)" option of "Use Compiled File?" setting in the admin panel.

 
The default setting is "Yes (and included files)", but with this setting selected, wireRenderFile() cannot receive its optional array parameters. Is it a bug or a feature?
 
I also tried to switch to "No", but this option cannot be saved, after saving the template it switches back to "Yes (and included files)". Again, bug or feature? :)
 
All my template files begin with <?php namespace ProcessWire; so in this case is this automatic namespace updating necessary at all?
 
I don't know how this compiling thingy works, so I do not know what the right answer to this "Use Compiled File?" question should be.
 
Is it ok to use "Yes (and included files)"?
Or should I use "No" (if it was possible)?
Or "Yes (and includes files)" which renders wireRenderFile() sort of useless?
 
Any help is appreciated!
Posted

I used wireRenderFile()  method only in PW 2.7.x

may be it will be needed some tests in PW 3.x in order to see how it works.

I think that is OK to use "YES (template file only)"

Yes and includes files option maybe causes trouble because tries to compile

non compileable files in between.

Personally do not know about that at the moment.

Posted

Thanks clsource! It would be nice to learn more about this compilation feature. So far, I have not found anything that describes it in detail. Any good articles or forum posts on it?

Posted

I read the article so now at least I get the basics of this new feature.

 
Issue 1
 
One thing is really confusing about how it works:
- I deleted the "FileCompiler" folder in "cache"
- I set the compile option of a template to "Yes (template file only)"
- "FileCompiler" folder and its content was re-generated
- I reloaded a page of the frontend and the wireRenderFile("partials/top_nav.inc.php", $_p); call ran fine
- I set the compile option to the default "Yes (and included files)"
- I reloaded a page of the frontend and the cached/compiled version of the template file of that page did NOT change. I suppose this is because the original template file did not change either.
 
However, this can be confusing, because later on I might easily change the original template file, and the cached/compiled version will change to this (which fails to run):
 
$layout =  wireRenderFile(\ProcessWire\wire('files')->compile("layout/home.inc.php",$_p,array('includes'=>true,'namespace'=>true,'modules'=>true)));
 
So the problem will only crop up later on, just to "surprise me" a little bit, which is not the best experience ever :)
 
Issue 2
 
I have just created a gif screen-grab to show you what happens when I try to use the "No" option:
post-4029-0-60328800-1451899743_thumb.gi
 
  • 1 year later...
Posted

After upgrading from 2.7.2 > 3.0.61 i now receive this error:

Call to undefined function wireRenderFile()

Looks like an issue with including files and the compiler?

ui.php includes _init.php - works
ui.php includes _init.php which includes file2.php - does not work within file2

This previously worked with 2.7.2

[SOLVED] - I moved my _init.php file from the main ui.php template, and used $config->prependTemplateFile = '_init.php'; which has resolved the issue. Still curious as to why this worked before upgrading.

Posted

The file compiler, which adds the ProcessWire namespace in 3.0 does not touch (and even can't touch) files, which are included via include()/require(), but only things like modules / templates and files included by processwire functions like wireIncludeFile / wireRenderFile. 

Posted

Ok, so I'm still having some issues:

wireIncludeFile($file, $data);

Inside the $file, I'm setting up some variables, but they don't appear to be set in the current scope.

ie:

wireIncludeFile($file, $data);
echo $test;

Where $test = "test"; inside $file;
If it's a regular include, shouldn't these variables be available after the wireIncludeFile function?

Posted
1 hour ago, Mackski said:

If it's a regular include, shouldn't these variables be available after the wireIncludeFile function?

But it's not a regular include - you are using the wireIncludeFile() function so function scope applies.

You can change to a regular include if you don't want limited scope for the included file.

Posted

Regular include doesn't work. I get an error because I'm using wireRenderFile inside my included file: Call to undefined function wireRenderFile()

This used to work on 2.7 so not sure what's changed.

Posted
17 minutes ago, Mackski said:

I get an error because I'm using wireRenderFile inside my included file: Call to undefined function wireRenderFile()

That's a namespace issue. Either add...

namespace ProcessWire;

...at the top of your template file, or call the function including the namespace...

\ProcessWire\wireRenderFile($filename)

 

  • Like 1
Posted

ProcessWire 3 changed to using namespaces. In places where processwire can control loaded files (like wireRenderFile() or template files) it does have a file compiler to add the namespace on demand into the file. This is not possible with include() because there's no place to change the loaded file on demand, because it's all handled by php. So if your really need to use include() for the reason of sharing the variable scope you need to make sure to add the namespace manually in the included files.

  • Like 1

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
×
×
  • Create New...