We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Advantages of using views/layout/main.volt vs everything in views/index.volt?

What are the advantages of using views/layout/main.volt vs having everything just be in views/index.volt?

The INVO app has navigation broken out into main.volt, but it seems the output would be identical if that code was just included in index.volt.

When would you want it broken out, and why?

Thanks!



125.8k
Accepted
answer

To reduce duplication. If you have multiple pages, you don't want to have to re-type the navigation on every page, so you break it out into its own file. I use partials for this, but there is probably a better way.



7.7k

That would already be accomplished by putting the navigation in views/index.volt (as opposed to views/whatever/index.volt, which is controller-specific).

But I guess if your top navigation was completely different in different controllers that wouldn't work, and having different layout views would make sense.

Thanks