PaulAik Posted March 28, 2015 Share Posted March 28, 2015 Wondering if I can render out partial content via the API, and pass through either the current page, or a set of variables. E.g. instead of this: $content = "<h1>This is the content</h1>"; I'd love to do this: $content = $something -> render('/site/templates/views/partials/partialcontent.html.php', $page); I've seen in the API docs the ability to render pages as partials, but I think this is a bit different (e.g. partialcontent isn't a page itself). 1 Link to comment Share on other sites More sharing options...
PaulAik Posted March 28, 2015 Author Share Posted March 28, 2015 Possibly answering my own question here... will wireRenderFile do the trick? https://processwire.com/blog/posts/processwire-2.5.2/#new-wirerenderfile-and-wireincludefile-functions 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 28, 2015 Share Posted March 28, 2015 That's exactly what you want to have. wireRenderFile() and $page->render($options) should be enought to fit the needs here. 2 Link to comment Share on other sites More sharing options...
qtguru Posted March 28, 2015 Share Posted March 28, 2015 Seriously guys why don't i know about this ? now this will make things a lot more better Link to comment Share on other sites More sharing options...
adrianmak Posted April 2, 2015 Share Posted April 2, 2015 That's exactly what you want to have. wireRenderFile() and $page->render($options) should be enought t The example code shown in the blog post, $photo = $page->photos->getRandom(); $sidebar = wireRenderFile("inc/fancy_sidebar", array('photo' => $photo)); the wireRenderFile() function will auto append .php file extension to fancy_sidebar ? Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 2, 2015 Share Posted April 2, 2015 Yeah, it does append .php if no extentions is given. Link to comment Share on other sites More sharing options...
adrianmak Posted April 5, 2015 Share Posted April 5, 2015 I tried testing the wideRenderFile but no success. a template file $temp = wireRenderFile("test", array('content' => $page->body)); echo $temp; test.php <?php $content .= "AAAAAAAAAAAAAA"; There is not outputted content of $temp. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 5, 2015 Share Posted April 5, 2015 wireRenderFile does return the output of the included file. So everything you echo in test.php will be returned to $temp as string. The passed variables are only made available as copies, but they do not automatically make the function return anything. 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