{% block content %} {% endblock %} VS {{ content() }}

What is the difference (pros and cons) and what should I use in my projects?

Thanks in advance.

{{ content() }} is used inside a top level view to call the relative layout view is defined.

{% block content %} {% endblock %} is used to declare a block that you can ovveride in a view that inherits from the view you declared the block.



21.8k
edited Jul '14

Hmm, in Vokuro app example they use {{ content() }} all the time no matter if it view to controller or public template layout or basic index.volt template in the views root. There has to be some reason for that that they have 3 levels of template and they all still using {{ content() }} and not {% block content %} {% endblock %}, Check it by yourself here: https://github.com/phalcon/vokuro/tree/master/app/views



5.4k

I guess you should read/study http://docs.phalconphp.com/en/latest/reference/views.html#hierarchical-rendering

({{ content() }} is Volt syntax for the getContent() method)

(IMO it's more flexible to use blocks & extend tpl's)



793
edited Aug '14

I am using blocks when I need to load css and javascript scripts. In my main layout I load only important libraries, which are needed for whole site, but some of my page if using another css or javascript file I put it into block and load it as an additional file. So when I open another page this additional files are not called, except that they are not cached.