Jump to content

[Solved] wireRenderFile file/path errors


rick
 Share

Recommended Posts

Howdy!

I've been exploring using the wireRenderFile() function in a test module. I keep getting one error or another depending on how I attempt to render the file. According to the api doc one of the default paths is /site/modules/. In this directory I have my module, which has a sub directory for files to be rendered as needed.

$file = "somefile.php";
$path = $this->wire('config')->urls('siteModules')."myModule/includes/";
$result = wireRenderFile($file, array(), array('allowedPaths' => "$path"));
return $result;
// Error: Filename doesn't exist: ***/site/templates/somefile.php

It appears that wireRenderFile is not accepting the allowedPaths option.

Tracy dump shows $path = ***/site/modules/myModule/includes/'.

Any ideas on what I am overlooking?

 

See last posting.

Link to comment
Share on other sites

The error is thrown from the wire/core/TemplateFile.php:171'/site/templates/somefile.php'.

line 170
	public function setFilename($filename) {
		bd($filename); // Shows invalid /site/templates/somefile.php
		if(empty($filename)) return false;
		if(is_file($filename)) {
			$this->filename = $filename;
			return true;
		} else {
			$error = "Filename doesn't exist: $filename";
			if($this->throwExceptions) throw new WireException($error);
			$this->error($error);
			$this->filename = $filename; // in case it will exist when render() is called
			return false;
		}
	}

 

Link to comment
Share on other sites

Unless something's changed, you are tied to having the file somewhere within /site/templates/  by default.

Edit: I see you are providing an exception using $path...hmmm. So, it should work

Edited by kongondo
Link to comment
Share on other sites

Ok, apparently the term 'PATH" means the complete filespec (path + file). I still cannot get the allowedPath parameter to accept any entry. It always uses /site/template.

I did however get this to work by providing the filespec as the first parameter. So from my first example,

$file = "somefile.php";
$path = $this->wire('config')->urls('siteModules')."myModule/includes/";
$filespec = $path . $file;
$result = wireRenderFile($filespec);
return $result;

works just fine, so I will mark this topic as solved.
Can anyone reproduce this behavior? Just checking to see if this is a bug or my stupidity. ?

Link to comment
Share on other sites

  • rick changed the title to [Solved] wireRenderFile file/path errors
1 hour ago, rick said:

Can anyone reproduce this behavior?

As far as I can see it's working as per the documentation for the method - wireRenderFile() just calls $files->render(): https://processwire.com/api/ref/wire-file-tools/render/

Quote
filename string

Assumed relative to /site/templates/ unless you provide a full path name with the filename. If you provide a path, it must resolve somewhere in site/templates/, site/modules/ or wire/modules/.

 

5 hours ago, rick said:
$result = wireRenderFile($file, array(), array('allowedPaths' => "$path"));

If you do set an additional allowed path (which in your case you don't need to do because files within /site/modules/ are allowed by default) then the allowedPaths option needs to be an array of extra allowed paths.

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...