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

include header and footer file separately in project

i want to include header.php and footer.php in whole project in and all css and javascript how could i do it conveniently in phalcon please explain with example

Do you mean in your View or in every Controller? A little more detail would be helpful.

in view part only

Volt has the {{ partial }} tag. Also, you can include raw PHP in Volt templates.



2.2k

It sounds like you're just jumping in to Phalcon and MVC from a more classic style of setting up sites. Take your time and really leverage the documentation.

I think if you hit the docs, and prepare to shift your mindset on how to assemble sites, you should pick up the "Phalcon way" pretty quickly.

Check out: https://docs.phalcon.io/en/latest/reference/views.html

You can set up your main "outer" template in app/views/index.volt, and then the individual page "inner" templates go into files like app/views/index/index.volt and app/views/about/index.volt and so on. Any data preparation or logic will go into the controller files in app/controllers/IndexController.php and app/controllers/AboutController.php and so on. The routing will take care of putting it all together.

  • app/
    • controllers/
      • IndexController.php // logic for index page
      • AboutController.php // logic for about page
    • views/
      • index.volt // "outer" template with header, footer, and css.js includes (all pages load this)
      • index/
        • index.volt // "inner" template for index page
      • about/
        • index.volt // "inner" template for about page

Hope this helps!

What you could do is create a index view folder and have your content in that folder, and have an index.volt or phtml with your header and footer.