Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:48:29+00:00 2026-05-25T02:48:29+00:00

Why Twig documentation recommends to use extending rather than including? Symfony 2 documentation says

  • 0

Why Twig documentation recommends to use extending rather than including? Symfony 2 documentation says because “In Symfony2, we like to think about this problem differently: a template can be decorated by another one.” but nothing more. It’s just author’s whim or something more? Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:48:29+00:00Added an answer on May 25, 2026 at 2:48 am

    When to use inheritance:

    You have 50 pages sharing the same layout – you create a layout.twig as a parent, and each page extends that layout.twig. So the parent is the generic and the child is the specific.

    When to use include:

    Out of the 50 pages, there are 6 pages that share a chunk of HTML – you create a shared-chunk.twig and include it in those 6 pages.

    Another usage:

    You notice that your layout.twig is bit cluttered and you would like to modularize it, so you split sidebar.twig into a separate file and include it in layout.twig.

    Can you use include for the inheritance use-case:

    Sure, create chunks for header, footer and what have you, and use includes in each of the 50 pages. But that’s wrong design as explained above.

    Can you use inheritance for the include use-case:

    Sure, create an empty block for the shared chunk in the parent layout.twig, and create a second level child layout-with-chunk.twig that extends layout.twig and fills in the chunk block, and the 6 pages in the above example that share the chunk can then extend layout-with-chunk.twig instead of layout.twig. But this again is wrong design because the chunk block is not shared by all children and shouldn’t go into the base parent. Plus you have cluttered the inheritance tree.

    So:

    As explained above – it’s a matter of design not programmability. It’s not about: I can achieve this same result using a different programming technique, its about which usage is better design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Twig (inside Symfony2) to debug a variable that contains a
I am trying to alter the date_widget using symfony2 and twig. I would like
In Twig template I check if a field has an error like this: {%
I use .twig templates on a website however I need to get pretty crafty
Does Smarty3 has the in operator that works like Twig's one: {% if option
I use embedded controller to render form that's used on multiple pages: Twig {%
I have a weird problem with twig in Symfony2. I am using the following
My question: How do I permit use of debug in Twig templates within Silex?
I'm trying to create a link with an anchor like www.example.com/services#anchor1 in my Twig
For rendering form errors in a twig template, you just have to use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.