Pass model attribute into main.php (layout file)

In my main.php layout file I have a contact form at the bottom, I have a model ContactForm which I can define as $contact, but how do I pass this into the main.php file?

I tried passing it in via SiteController - actionIndex() but that does not seem to work.

The best approach i see is for you to make the contact form a widgets and call it in your layout file

I have no idea how to make a widget.

Anyway I’ve put the contact form in my index.html file and I’m having the same problem. I’ve passed $contact in via actionIndex() in SiteController but it’s still complaining that contact is undefined. Surely this should work.

I don’t think your view is rendered in the same context as the rest of the layout, so that won’t work. Learn to make a widget (check the MainMenu widget in the base layout of a newly generated webapp and/or checkout this cookbook article to get started) and make a widget, it’s the right way to do this.

I understand what you’re saying regarding the layout, but I’ve now put the form in index.html and it does not work there either. The same form is in contact.html and it works fine there.