BUCKHORN Posted October 9, 2013 Posted October 9, 2013 How do I change $page->template->filename in a module? I'm using a the page render hook before and no combination of attempting this has worked. To further confuse me... I can't even set the variable in a template directly or using set().
BUCKHORN Posted October 9, 2013 Author Posted October 9, 2013 Copied from the helloworld module and modified. public function changeFilename($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; $page->template->filename = wire('config')->paths->themes.wire('config')->theme->name.$page->template.'.php'; $event->return = $page->template->filename; //wire('template')->filename = wire('config')->paths->themes.wire('config')->theme->name.$page->template.'.php'; //wire('page')->template->filename = wire('config')->paths->themes.wire('config')->theme->name.$page->template.'.php'; } in the template i tried $page->template->set('filename','/httpdocs/tmp/site/templates/dev/basic-page.php'); $page->template->filename = '/httpdocs/tmp/site/templates/dev/basic-page.php'; The $config variables are working fine, but I also tried hard coding the path. No luck, tried both production and newest dev release. I must be missing something.
Soma Posted October 9, 2013 Posted October 9, 2013 Setting template filename only works if it starts with full root path. Make sure your paths are correct. The root path you have you can see with: $this->config->paths->root So $this->config->paths->templates . "view/mytpl.php"; works fine in a hook I don't think you can set the template filename in the template for the page as it's already rendering it. Also $event->return = $page->template->filename; isn't needed if it's in a before render hook. 1
BUCKHORN Posted October 9, 2013 Author Posted October 9, 2013 Thanks Soma, I really appreciate your help. I'll try this out.
BUCKHORN Posted October 9, 2013 Author Posted October 9, 2013 No such luck Soma. I tried all of the following in the module. The paths are correct. $this->template->filename = $this->config->paths->templates . "view/mytpl.php"; $page->template->filename = $this->config->paths->templates . "view/mytpl.php"; wire('page')->template->filename = $this->config->paths->templates . "view/mytpl.php"; wire('template')->filename = $this->config->paths->templates . "view/mytpl.php";
Soma Posted October 9, 2013 Posted October 9, 2013 I'm doing it also here https://github.com/somatonic/BlocksContent/blob/master/BlocksContent.module Works fine. Can't say except that the path has to be correct and file exist or it will ignore it. Also maybe the context or hook is different in your code. 1
BUCKHORN Posted October 10, 2013 Author Posted October 10, 2013 Can't say except that the path has to be correct and file exist or it will ignore it. Ah, I didn't realize the file had to exist. Problem solved. Thank you so much!
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