fliwatuet Posted November 18, 2016 Share Posted November 18, 2016 Hello! I dropped out on trying to use processwire, but I will give it a new try. So after reading some tuts (again) and much better understanding of the concept, there are of course new questions. I am using the latest pw 3.0 and the intermediate profile, so it is "delayed output" for me. My first question is how to output all the fields in a page? (Ryans planet tutorial) When I use $content=$page->planet_summary; then I get the content of this field. But how to output the fields "planet_age" and "planet_type" in the template file "planet.php"? So, I did some research and found "How to Create an AJAX Driven Theme for ProcessWire". Ok, let's concatenate the fields: $content=$page->planet_age . "<br/>" . $page->planet_type . "<br/>" . $page->planet_summary; So far so good, all is fine and working. But what to do when I use let's say 50 fields? There has to be a better method, also to arrange the fields with e.g. bootstrap. How can I do this? Link to comment Share on other sites More sharing options...
Pixrael Posted November 18, 2016 Share Posted November 18, 2016 Read this for some insight https://processwire.com/talk/topic/12969-intermediate-template-structure-without-string-concatenation/ 2 Link to comment Share on other sites More sharing options...
fliwatuet Posted November 18, 2016 Author Share Posted November 18, 2016 Thanks! Output bufferings seems to be the easiest solution, but ain't this an objection to the delayed output? Are there any other drawbacks? The Wire Render Pattern also looks pretty easy to understand and implement. Link to comment Share on other sites More sharing options...
clsource Posted November 18, 2016 Share Posted November 18, 2016 you could use the wireRenderFile method. all $page properties could be used inside the html // templates/planets.php $content = wireRenderFile('views/planets'); // templates/views/planets.php <html> <body> <?php echo $page->title ?> </body> </html> see https://github.com/NinjasCL/wire-render-pattern 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 19, 2016 Share Posted November 19, 2016 6 hours ago, fliwatuet said: Output bufferings seems to be the easiest solution, but ain't this an objection to the delayed output? Output buffering works great with delayed output. Set variable default in your auto-prepended init.php: $sidebar = $page->sidebar; Override in your template as needed: <?php ob_start(); // $sidebar ?> <div class="special-promo"> <h2>My special promo sidebar</h2> <?= $page->special_promo ?> </div> <?php $sidebar = ob_get_clean(); ?> Output in auto-appended main.php: <div class="sidebar"> <?= $sidebar ?> </div> I have never entirely understood the benefit of $files->render(), aka wireRenderFile(). Seems to be similar to an include, but with limited variable scope. Personally I'd rather use includes for shared partials so I can get and set any variable inside the partial without needing to explicitly pass variables back and forth from template to rendered file. I've never had to deal with so many variables that I'm losing track of their names and accidentally overwriting them or anything like that. 7 hours ago, fliwatuet said: My first question is how to output all the fields in a page? It is possible to get all fields in a page and loop over them: foreach($page->fields as $field) { $field_content = $page->get($field->name); // output $field_content } But there are few situations where this would be useful, because usually you are using several different types of field on a page which return different types of data (string, WireArray, PageImage, etc) and need different markup output. So most of the time you want to get individual fields by name. Link to comment Share on other sites More sharing options...
fliwatuet Posted November 19, 2016 Author Share Posted November 19, 2016 Thanks! I think I will give output buffering a shot, seems to be the simplest solution. Link to comment Share on other sites More sharing options...
szabesz Posted November 20, 2016 Share Posted November 20, 2016 On 11/19/2016 at 3:11 AM, Robin S said: I have never entirely understood the benefit of $files->render(), aka wireRenderFile(). Seems to be similar to an include, but with limited variable scope. Just for the record: "I also tend to store additional properties in $page rather than creating global variables (e.g., $page->foo = 'bar' instead of $foo = 'bar'), which makes it a lot easier to use wireRenderFile(). As long as you pass in $page, you know you've got everything you need, and you can add more properties later without worrying about updating your "view bag." 1 Link to comment Share on other sites More sharing options...
pwired Posted November 20, 2016 Share Posted November 20, 2016 Delayed output and WireRenderFile() seems to be such a returning topic, especially lately, it should get a dedicated place in the forum. Link to comment Share on other sites More sharing options...
fliwatuet Posted November 21, 2016 Author Share Posted November 21, 2016 Maybe it should be mentioned in the tutorials, how to do this. 1 Link to comment Share on other sites More sharing options...
szabesz Posted November 21, 2016 Share Posted November 21, 2016 4 hours ago, fliwatuet said: Maybe it should be mentioned in the tutorials, how to do this. True. There are plans to do it: https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page5 But this project of @ryan seems to be stalled. Link to comment Share on other sites More sharing options...
pwired Posted April 22, 2018 Share Posted April 22, 2018 Quote As long as you pass in $page, you know you've got everything you need, and you can add more properties later without worrying about updating your "view bag." The wire render pattern (by clsource) is just another example of how you can use the amazing potential of Processwire. Instead of the $viewBag you can use any other $dataBag as you see fit that not need to be updated inside _main.php Processwire now also has the region() function and fields can use a template for even more file and code organization. 2 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