Twig blocks are like methods in a class.  If the Twig container is a class, Twig blocks are methods.  So you can call on a parent Twig view and extend the parent just like a function using the “parent()” function like below within the dynamic content tags, which are a pair of squiggly brackets.  Here’s an example of how you can extend a parent’s block from a child view.

{% extends “MainBundle::Base:main.html.twig” %}

{% block Css %}
   {{ parent() }}
   <link rel="stylesheet" href="addUniqueStylesheetForThisView.css">
   <link rel="stylesheet" href="addAnotherStylesheet.css">
{% endblock %}

Without using “parent()” above, this child “Css” block will completely override the parent’s Css block.  As the title states, this is easy, useful and helps your code stay “DRY” – Don’t Repeat Yourself.

Is your company still not on a PHP framework?  Do you feel you need to modernize your company’s web, code, systems, databases and infrastructure?  Consider a “Business Systems Audit” by Belchamber Business Consultants, they will help you cut costs, improve your web development workflow, all while improving the stability of your code and systems and making your entire organization more effective.  PHP Symfony experts can help shed light on your I.T. and/or web development department.  Maybe it’s time to shake things up?


In the newest versions of Symfony greater than 2.2 you can embed output from controller by calling it with this handy TWIG snippet:

{{ render(controller('PostBundle:Posts:recentPosts', { 'category': 'cool symfony tips' })) }}

Check out Sensio Lab’s documentation to learn more.

This is especially useful if you want to create a snippet that will deliver content independent of the controller you are calling the main content of the page — stuff around the periphery.  As long as you aren’t using any logic, this is an acceptable use of MVC and it decouples say content in a related widget on the page from the controller of the page’s main content.  This separation of concerns ensures the controller of the main content stays as lean and clean as possible!