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

Difference between a partial and a layout? And when to use what?

I am trying to learn phalcon and have been writing up an application while doing so. I am now at a stage where I need to separate common elements from a view. I read up on partials and layouts documentation. What I am confused with is which to use when and what’s the difference between the two? Any help is appreciated. Thank you.



11.2k
Accepted
answer
edited Aug '14

Layout is a layout.... for set header and footer and partials is for example:

Layout can be:

  1. Layout for blog
  2. Layout for homepage etc.

And partials it could be:

  1. blog post
  2. Part or element or some widget or sidebar of homepage

For examle in index.phml of my index ( my homepage)

<div class='content'>
   <div class='left'>
       {{ partial('menu/main') }}
       {{ partial('widgets/tagcloud') }}
   </div>
   <div class='right'>
     // here is the content
   </div>
</div>

So you can partition some block of HTML or FULL elements to the partial and in the template you can include just the partial code for save lots of lines with repeating the code.