0

If i have AlphaBunde that is parent of BetaBundle how can i extend a twig block without overriding the entire template?

How can i import the routes that exist only in BetaBundle?

jury89
  • 302
  • 3
  • 16

2 Answers2

3

You cannot extend a block in Twig. You can overload it if you extend a template (and call parent() which kind of works as inheritance).

If you extend bundle you can overload its controllers or resources. I don't think you can really extend a template from a parent bundle because of how the paths are resolved. You can read more about it in the Extending a Bundle documentation chapter.

Also, How to use Bundle Inheritance to Override parts of a Bundle might clarify few things.

Remember to check Overriding Bundle Templates to learn how to overload templates in an application.

About routes: I think you'll have to define each route in your application's configuration file if you want to import them selectively.

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
0

If you want to use template from another bundle and you do not want to override whole template you use this:

// Your file in ProjectAplhaBundle index.html.twig

{% extends "ProjectBetaBundle::layout.html.twig" %}

{% block content %}
    {{ parent() }}
    Somethings added to the existing content    
{% endblock %}

For routing from just BetaBundle remove all routes (routing.yml in app folder) and leave just one with something like this:

ProjectBetaBundle:
    resource: "@ProjectBetaBundle/Resources/config/routing.yml"
    prefix:   /

Then you specify all your routes in @ProjectBetaBundle/Resources/config/routing.yml

I hope that helps. Cheers

TroodoN-Mike
  • 15,687
  • 15
  • 55
  • 78
  • 1
    i know that normally i can use these commands, but my `BetaBundle` has a `getParent()` function, and i can't use `{% extend "AlphaBundle::layout.html.twig" %}` in `BetaBundle` because it generate a loop. – jury89 Jan 27 '12 at 09:21