rick Posted March 22, 2022 Posted March 22, 2022 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.
horst Posted March 22, 2022 Posted March 22, 2022 I believe you must use pathes, not URLs: $path = $this->wire('config')->paths('siteModules').'myModule/includes/'; ---------------------------------^
rick Posted March 22, 2022 Author Posted March 22, 2022 I thought so as well. I tried with both urls and paths. I get the same error stating templates but tracy shows the path is correct.
rick Posted March 22, 2022 Author Posted March 22, 2022 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; } }
kongondo Posted March 22, 2022 Posted March 22, 2022 (edited) 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 March 22, 2022 by kongondo
rick Posted March 22, 2022 Author Posted March 22, 2022 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. ?
Robin S Posted March 22, 2022 Posted March 22, 2022 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. 2
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