Basically in default.ctp I have this for my title:
= $this->fetch(\'title\') ?>
And inside of the
fetch() returns the contents of a block not a variable. Using set() in your Controller is setting a variable that can be output in your View templates by echoing the variable:-
If you want to use fetch() you need to use it in combination with assign() in the View templates to define the block. For example in your View template use:-
assign('title', $title); ?>
And then in the layout template:-
fetch('title'); ?>
In CakePHP 3 the idea is to set the page title by assigning it in the View as it relates to the rendering of the page. This differs from how this was originally handled in CakePHP 2 where you'd define title_for_layout in your controller and then echo the $title_for_layout variable in the layout template (this was deprecated in favour of the CakePHP 3 approach in later versions of Cake 2).