Jeremy
Jeremy

Reputation: 3809

Reuse template in CakePHP 3?

Lets say I have a template default.ctp, is there anyway that I can use that template for multiple controllers or set it as a fallback template when a template is missing?

Ex: localhost/users/login/ calls UsersController->login which tries finding login.ctp. If login.ctp is missing can I make it use default.ctp instead?

Upvotes: 0

Views: 164

Answers (1)

Gaurav
Gaurav

Reputation: 1972

default.ctp is a layout file which will be used in all cases unless you specifically instruct not to by :

$this->viewBuilder()->layout('');

While login.ctp in your example is a view file for the login action. So, they are not alternatives but partners which combine to display the final output. layout/template will always be there irrespective of the presence of view file. If you don't want to display output using any file. Just write :

$this->render(false);

or

$this->autoRender = false;

where view file is called only when you specifically call Controller::render() method.

Upvotes: 1

Related Questions