Gazley Posted July 7, 2013 Share Posted July 7, 2013 Hi there, I have a "partial" based system where I have a class name (some_partial.php) and an associated ".html" file (some_partial.inc). If the class exists as a "partial", when rendered, it creates a TemplateFile using the path to its associated .html file. I've now a scenario where there are advantages to have the data that was in the .html file actually stored in a PW "page" (/partials/some_partial). When the partial instantiates, if it can't find a disk based .html file, it checks to see if there is a PW "page based partial". The HTML is in the page's body field. However, TemplateFile wants a file path to construct an instance. Is there a way to get a TemplateFile instance using the html data in my $page->body memory variable? Thanks. Link to comment Share on other sites More sharing options...
Wanze Posted July 7, 2013 Share Posted July 7, 2013 You can construct a TemplateFile object without a filename, but there will be a problem with the render method if you haven't set a filename: public function ___render() { if(!$this->filename || !is_file($this->filename)) return ''; You could hook after TemplateFile::render() and check for the return value. If it's empty, return your $page->body content. 2 Link to comment Share on other sites More sharing options...
Gazley Posted July 7, 2013 Author Share Posted July 7, 2013 Thanks Wanze - that's a nice suggestion. 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