Jump to content

TemplateFile - how to create without existing disk file


Gazley
 Share

Recommended Posts

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

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.

  • 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...