szabesz Posted January 3, 2016 Share Posted January 3, 2016 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! Link to comment Share on other sites More sharing options...
clsource Posted January 3, 2016 Share Posted January 3, 2016 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. Link to comment Share on other sites More sharing options...
szabesz Posted January 3, 2016 Author Share Posted January 3, 2016 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? Link to comment Share on other sites More sharing options...
clsource Posted January 3, 2016 Share Posted January 3, 2016 Not sure if there are more detailed documents, for now I found this https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#compiled-template-files 1 Link to comment Share on other sites More sharing options...
szabesz Posted January 3, 2016 Author Share Posted January 3, 2016 Thanx a lot! I'm going to read it. Link to comment Share on other sites More sharing options...
szabesz Posted January 4, 2016 Author Share Posted January 4, 2016 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: Link to comment Share on other sites More sharing options...
adrian Posted January 4, 2016 Share Posted January 4, 2016 The undefined variable error has been fixed in today's commits to the devns branch. Link to comment Share on other sites More sharing options...
szabesz Posted January 4, 2016 Author Share Posted January 4, 2016 Thanks for letting us know! Link to comment Share on other sites More sharing options...
adrian Posted January 4, 2016 Share Posted January 4, 2016 And the saving as "No" should be fixed now also! https://github.com/ryancramerdesign/ProcessWire/commit/c485972f70bc436bc203ceefb22bbf314ed826fd Link to comment Share on other sites More sharing options...
szabesz Posted January 4, 2016 Author Share Posted January 4, 2016 Thanks once more Link to comment Share on other sites More sharing options...
Mackski Posted June 9, 2017 Share Posted June 9, 2017 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. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 12, 2017 Share Posted June 12, 2017 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. Link to comment Share on other sites More sharing options...
Mackski Posted June 13, 2017 Share Posted June 13, 2017 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? Link to comment Share on other sites More sharing options...
Robin S Posted June 13, 2017 Share Posted June 13, 2017 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. Link to comment Share on other sites More sharing options...
Mackski Posted June 13, 2017 Share Posted June 13, 2017 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. Link to comment Share on other sites More sharing options...
Robin S Posted June 13, 2017 Share Posted June 13, 2017 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) 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 13, 2017 Share Posted June 13, 2017 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. 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