Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render fields doesn't work as expected when run outside of PW templates #1105

Open
dragan1700 opened this issue Feb 28, 2020 · 1 comment
Open

Comments

@dragan1700
Copy link

Short description of the issue

The call to $child->render('offer_matrix'); is not resulting in rendering of a field, but rather a page - it's looking for "offer_matrix" in site/templates/, instead of "offer_matrix.php" in site/templates/fields/.
This works as expected in a regular PW template, but it doesn't when run inside Tracy Debugger console (and perhaps also when PW is bootstrapped - but I did not test that at this point).

$myOffer = 11404;
$myOfferPage = $pages->get($myOffer);
// using absolute path doesn't work:
$str = wireRenderFile("/home/domainname/www/dev.mysite/site/templates/offer-index-dev.php", array("offer_index_page_id" => $myOffer));
// using relative path doesn't work either: (default is site/templates/ - according to docs)
$str = wireRenderFile("offer-index-dev.php", array("offer_index_page_id" => $myOffer));
// using relative path without .php suffix doesn't work either: (according to docs .php suffix can be omitted)
$str = wireRenderFile("offer-index-dev", array("offer_index_page_id" => $myOffer));

// $str is then used to generate a PDF and save it to a page - but the error appears above this
// fatal error msg: * Exception: Invalid output file location or specified file does not exist. on line: 518 in /home/mydomain/www/dev.mysite/wire/modules/PageRender.module

inside offer-index-dev.php, the relevant place where the error is triggered:

foreach($offer_index->children as $child) {
	echo $child->render('offer_matrix'); // that's where PW gives up and terminates
	// echo $child->render('/home/mydomain/www/dev.mysite/site/templates/fields/offer_matrix.php', $vars = ["pid" => $child->id]); // I've tried again with abs. path here
	// echo $child->render('/home/mydomain/www/dev.mysite/site/templates/fields/offer_matrix'); // ... and abs. path w/o .php suffix here
}

Expected behavior

I would expect that PW renders the field templates like it does when run from inside a "normal" PW template. Especially in the case where I use the absolute path, incl. file-suffix.

Actual behavior

Exception: Invalid output file location or specified file does not exist. on line: 518 in /home/mydomain/www/dev.mysite/wire/modules/PageRender.module

The call to $child->render('offer_matrix'); is not resulting in rendering of a field, but rather a page - it's looking for "offer_matrix" in site/templates/, instead of "offer_matrix.php" in site/templates/fields/.

Steps to reproduce the issue

  1. Create field templates, as described here https://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/#field-rendering-with-template-files
  2. Create a page that uses these fields.
  3. In the Tracy Debugger console, use some similar code as posted above in the short description.
  4. Try to get a value back when you run wireRenderFile()
  5. Use the same code to output fields inside a regular PW template - you should see it there working just fine.

Setup/Environment

  • ProcessWire: 3.0.147
  • PHP: 7.2.27
  • Webserver: Apache
  • MySQL: 10.1.44-MariaDB
@adrianbj
Copy link

adrianbj commented Mar 2, 2020

@ryancramerdesign - even though this issue seems to be due to it trying to render the template, rather than the field, I wonder if this issue is also at least a bit related to #511

It would be great if you could also test that again while you are looking into this one because so many of us are using Tracy's Console panel for code testing and this is the one area where there seems to be problems.

FYI - this (https://github.com/adrianbj/TracyDebugger/blob/7d1209394d34c00991296159187754a0b6bd9ce5/includes/CodeProcessor.php#L120-L153) is where the Console Panel instantiates a new template file and renders it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants