interrobang Posted January 23, 2014 Share Posted January 23, 2014 I have a setup with several templates without a templatefile. But I want to render some of the pages using these templates with $page->render($filename). I think I did not understand how the $page->render options work. A simple example: In the default profile I just delete the "basic-page.php" file and create a new file "basic-page-alt.php" with this simple code <?php // basic-page-alt.php echo "<h1>$page->template</h1>"; and I modify the home.php file to<?php // home.php include("./head.inc"); echo $pages->get('/about')->render("basic-page-alt.php"); include("./foot.inc"); When I try to view the homepage I get an errorError: Exception: Template file does not exist: '/XXX/Sites/pw_test/site/templates/basic-page.php' (in /Users/XXX/pw_test/wire/core/TemplateFile.php line 67) When I put a empty "basic-page.php" back in my templates folder I get the expected result. I am using the latest dev from github. Is this the intended behaviour? 1 Link to comment Share on other sites More sharing options...
cstevensjr Posted January 23, 2014 Share Posted January 23, 2014 From my extremely limited knowledge of ProcessWire, I believe you must always have the associated physical file (templatefile) in the /templates/ directory to echo anything. Link to comment Share on other sites More sharing options...
interrobang Posted January 23, 2014 Author Share Posted January 23, 2014 Thanks for the answer, but all my templatefiles are in "site/templates/" This way it works without having a "basic-page.php" file: include("./head.inc"); $p = $pages->get('/about'); $p->template->filename = $config->paths->templates . "basic-page-alt.php"; echo $p->render(); include("./foot.inc"); Shouldn't this be exactly the same as echo $pages->get('/about')->render("basic-page-alt.php") ? Link to comment Share on other sites More sharing options...
horst Posted January 23, 2014 Share Posted January 23, 2014 Hi interrobang, I cannot really follow what you are try to do - or I cannot find the specs for that the option can be a template filename: https://github.com/ryancramerdesign/ProcessWire/blob/dev/wire/modules/PageRender.module#L244 http://cheatsheet.processwire.com/ $page->render() also doesn't show anything, but it could be that there is missing newer stuff because ist seems to stick with the 2.3 stable. From where do you get that with the template filename? Link to comment Share on other sites More sharing options...
interrobang Posted January 23, 2014 Author Share Posted January 23, 2014 Hi Horst, sorry, I did not mention these are new features from the dev branch. Ryan added them some months ago: http://processwire.com/talk/topic/3145-multiple-views-for-templates/?p=32876 github commit 1 Link to comment Share on other sites More sharing options...
Soma Posted January 23, 2014 Share Posted January 23, 2014 I figured this also. There seems to be a difference. Set filename then render and render then specify template file. Calling with render with that option seems to try see if its viewable and It's not. Thus the error... there's not file.. and attaching your template would come after that. Only my guess without study code. 3 Link to comment Share on other sites More sharing options...
ryan Posted January 25, 2014 Share Posted January 25, 2014 When I put a empty "basic-page.php" back in my templates folder I get the expected result. I am using the latest dev from github. Is this the intended behaviour? This is not intended behavior. Good call. It's happening because the TemplateFile class is checking if the file it's given exists from the constructor rather than from the render() method. The PageRender module gets a copy of the TemplateFile instance from the Page, and then changes the filename if you've given if one. As a result I think I can solve this just by moving the "file does not exist" exception out of the TemplateFile constructor and to the render() method. I've just made the change, so it should appear in the next batch of commits to dev. 5 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