Jump to content

How to use a view file from other template


Ivan Gretsky
 Share

Recommended Posts

Good day, @teppo!

I have two templates (a and b) with different controllers, but same view file. So I want to make a use b's default view file in the render process. How do I do it?

I tried many things like the one below in the a's controller's init() method,  but without success.

$this->view->setTemplate('b');
$this->view->setView('default');

For now I am doing this in views/a/default.php:

<?php namespace ProcessWire; ?>

<?php include($config->wireframe['paths']['views'] .'home/default.php'); ?>

But maybe there is a better way?

Link to comment
Share on other sites

Hi @Ivan Gretsky

That's how it works for me. In your case, you can create a controller for 'b' template that extends your 'a' template, call the parent init method and then set template for the view

class PostsController extends CategoryController
{

	public function init()
	{
		parent::init();
		$this->view->setTemplate('category');
	}

}

 

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