cb2004 Posted July 6, 2015 Share Posted July 6, 2015 I am having some trouble passing variables using a new template technique I am trying. _main.php contains my main template with the line <?php echo $content; ?> I then have a template, lets say basic-page.php which contains: <?php $content = wireRenderFile("views/page"); include("./_main.php"); Within views/page.php I have a variable $JS. Why is that not appearing in my _main.php file? If I put the variable in basic-page.php it appears ok. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 6, 2015 Share Posted July 6, 2015 wireRenderFile does not inherit variables by default, that's not possible in php. But you can pass variables manually. // basic-page.php $js = "something"; $content = wireRenderFile("views/page", array("jsToFile" => $js)); include("./_main.php"); // views/page echo $jsToFile; 1 Link to comment Share on other sites More sharing options...
cb2004 Posted July 6, 2015 Author Share Posted July 6, 2015 Cheers for your reply Yes I have just discovered its not possible with PHP, I kind of knew it was but was curious. My current setup is: basic-page +includes views/page +includes main How would I pass something from views/page to main? Link to comment Share on other sites More sharing options...
cb2004 Posted July 6, 2015 Author Share Posted July 6, 2015 Ok, so its because I wish to show an error before the include call in main. Researching ways to do that now. Link to comment Share on other sites More sharing options...
cb2004 Posted July 6, 2015 Author Share Posted July 6, 2015 Spot of output buffering did the trick. Link to comment Share on other sites More sharing options...
Macrura Posted July 8, 2015 Share Posted July 8, 2015 @cb2004, care to share your solution for the community? Link to comment Share on other sites More sharing options...
Mackski Posted October 4, 2016 Share Posted October 4, 2016 I'm having a few issues with wireRenderFile in PW3. In my _init.php i have: // process site notes $data = array('notices',$notices); // $notices is processwire array $partials = wireRenderFile('views/partials/_notices',$data); Doesnt seem to work, I assume this has something todo with the File Compiler? Link to comment Share on other sites More sharing options...
Robin S Posted October 4, 2016 Share Posted October 4, 2016 22 minutes ago, Mackski said: $data = array('notices',$notices); That looks a bit strange to me. You are saying data is an array where the first value is the string 'notices' and the second value is the WireArray $notices - is that intentional? Or do you maybe mean: $data = array('notices' => $notices); 3 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