I'm using CakeEmail as follows:
$Email = new CakeEmail();
$Email->template('my_template', 'my_layout');
$Email->subject('My Subject');
// ...
How do I access the 'My Subject' value in my_layout.ctp?
The closest thing I could find was this but it's not very relevant. I'm looking at the CakeEmail::_renderTemplates() source code and it doesn't seem to do that but I'm not sure.
I know I can also pass the subject line to $Email->viewVars but that's not very flexible. Please advise!
Other than setting a View variable there is no way of doing this with
CakeEmail. However, you could extendCakeEmailso that the email's subject is added to the available variables in your template.I haven't tested this, but you should be able to do something like this:-
Here
CakeEmail::_renderTemplates()is extended to set the subject in the view variables (as long as it hasn't already been set elsewhere). You'd then use the extended class instead ofCakeEmaillike this:-Your View template would have a
$subjectvariable containing the email's subject.