Jump to content

Programmatically change page template in modules


bfncs
 Share

Recommended Posts

Hi there,

I'm currently writing a module that needs a Process action to generate some previewable HTML+CSS Code. In my code I'm doing something that boild itself down to this, to generate the preview:

public function executePreview() {
    $p = new Page();
    $p->template = $this->get('template'); // configurable module variable
    return $p->render();
}

Would be fine if this wouldn't render inside the default admin template (that I need for other actions of the same controller). This inserts a lot of CSS and JS that I can't use here.

The Preview action will be embedded into another action as an iFrame and I already tried calling it with ?modal=1 which get's rid of header, footer and sidebar, but still loads the CSS and JS.

What I'd like to do know is to programmatically change the template of this view, but I wasn't quite successful. I inserted this in the above code to make it render another inside my module folder, but it still renders inside the default admin template:

$this->page->template->set('filename', $this->config->paths->MyModule . 'my-blank-template.php');

While this would be pretty hackish, it also doesn't work... but I really hope that someone of you has a better answer to this problem?

With kind regards,

Marc

Edit: While stepping through the code I wondered, where exactly the $page->render() function is?

Link to comment
Share on other sites

Regarding the location of $page->render(): it's implemented as a hook in a module. What else could it be, this is ProcessWire :D.

See wire/modules/PageRender.module.

  • Like 1
Link to comment
Share on other sites

Ah, thanks so much, that was what I was looking for! That day had too much staring at code which makes you blind eventually. I'll try to work out the main question tomorrow, then, should be easier now.

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

×
×
  • Create New...